func (ss *SQLStore) Query(ctx context.Context, query Query) ([]Triple, error) {
	sq := `SELECT * FROM triples`
	where, args, err := getWhereClause(query)
	if err != nil {
		return nil, err
	}
	if where != "" {
		sq += fmt.Sprintf(" WHERE %s", where)
	}
	if query.Limit > 0 {
		sq = fmt.Sprintf("%s LIMIT %d", sq, query.Limit)
	}
	rows, err := ss.DB.QueryContext(ctx, sq, args...)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var triples []Triple
	for rows.Next() {
		var tri Triple
		if err := rows.Scan(&tri.Source, &tri.Predicate, &tri.Target, &tri.Weight); err != nil {
			return nil, err
		}
		triples = append(triples, tri)
	}
	return triples, nil
}
Query converts the given query object into SQL SELECT and fetches all the triples.
package fabric
import (
	"context"
	"database/sql"
	"errors"
	"fmt"
	"strings"
)
var (
	_ Store      = &SQLStore{}
	_ ReWeighter = &SQLStore{}
	_ Counter    = &SQLStore{}
)
type SQLStore struct {
	DB *sql.DB
}
func (ss *SQLStore) Count(ctx context.Context, query Query) (int, error) {
	sq := `SELECT count(*) FROM triples`
	where, args, err := getWhereClause(query)
	if err != nil {
		return 0, err
	}
	if where != "" {
		sq += fmt.Sprintf("WHERE %s", where)
	}
	if query.Limit > 0 {
		sq = fmt.Sprintf("%s LIMIT %d", sq, query.Limit)
	}
	var count int64
	row := ss.DB.QueryRowContext(ctx, sq, args...)
	if err := row.Scan(&count); err != nil {
		return 0, err
	}
	return int(count), nil
}
func (ss *SQLStore) Insert(ctx context.Context, tri Triple) error {
	query := `INSERT INTO triples (source, predicate, target, weight) VALUES (?, ?, ?, ?)`
	_, err := ss.DB.ExecContext(ctx, query, tri.Source, tri.Predicate, tri.Target, tri.Weight)
	return err
}