コード例 #1
0
ファイル: mysqlstore.go プロジェクト: kierdavis/argo
func (store *MySQLStore) Filter(subjSearch, predSearch, objSearch argo.Term) (ch chan *argo.Triple) {
	ch = make(chan *argo.Triple)

	queryClauses := make([]string, 0)
	queryValues := make([]interface{}, 0)

	if subjSearch != nil {
		subjectID := store.encodeSubject(subjSearch)

		queryClauses = append(queryClauses, "subject = ?")
		queryValues = append(queryValues, subjectID)
	}

	if predSearch != nil {
		predicatePrefixID, predicateLocal := store.encodePredicate(predSearch)

		queryClauses = append(queryClauses, "predicatePrefix = ?")
		queryClauses = append(queryClauses, "predicateLocal = ?")
		queryValues = append(queryValues, predicatePrefixID)
		queryValues = append(queryValues, predicateLocal)
	}

	if objSearch != nil {
		objectIsLiteral, objectID := store.encodePredicate(objSearch)

		queryClauses = append(queryClauses, "objectIsLiteral = ?")
		queryClauses = append(queryClauses, "object = ?")
		queryValues = append(queryValues, objectIsLiteral)
		queryValues = append(queryValues, objectID)
	}

	whereStr := ""
	if len(queryClauses) > 0 {
		whereStr = " WHERE " + strings.Join(queryClauses, " AND ")
	}

	resultChan, failChan := store.execute("SELECT subject, predicatePrefix, predicateLocal, objectIsLiteral, object FROM %s_triples"+whereStr, queryValues...)

	go func() {
		for row := range resultChan {
			var subject, predicate, object argo.Term

			if subjSearch == nil {
				subject = store.decodeSubject(row[0].(uint64))
			} else {
				subject = subjSearch
			}

			if predSearch == nil {
				predicate = store.decodePredicate(row[1].(uint64), row[2].(string))
			} else {
				predicate = predSearch
			}

			if objSearch == nil {
				object = store.decodeObject(row[3].(uint8), row[4].(uint64))
			} else {
				object = objSearch
			}

			ch <- argo.NewTriple(subject, predicate, object)
		}

		<-failChan
		close(ch)
	}()

	return ch
}
コード例 #2
0
ファイル: mysqlstore.go プロジェクト: kierdavis/argo
func (store *MySQLStore) decodeTriple(subjectID uint64, predicatePrefixID uint64, predicateLocal string, objectIsLiteral uint8, objectID uint64) (triple *argo.Triple) {
	return argo.NewTriple(store.decodeSubject(subjectID), store.decodePredicate(predicatePrefixID, predicateLocal), store.decodeObject(objectIsLiteral, objectID))
}