fabric
fabric copied to clipboard
Fabric is a simple triplestore written in Golang
WIP
Fabric
Fabric is a triple-store written in Go. Fabric provides simple functions
and store options to deal with "Subject->Predicate->Object" relations or so called
triples.
Usage
Get fabric by using go get -u github.com/spy16/fabric (Fabric as a library has no external dependencies)
mem := &fabric.InMemoryStore{}
fab := fabric.New(mem)
fab.Insert(context.Background(), fabric.Triple{
Source: "Bob",
Predicate: "Knows",
Target: "John",
})
fab.Query(context.Background(), fabric.Query{
Source: fabric.Clause{
Type: "equal",
Value: "Bob",
},
})
To use a SQL database for storing the triples, use the following snippet:
db, err := sql.Open("sqlite3", "fabric.db")
if err != nil {
panic(err)
}
store := &fabric.SQLStore{
DB: db,
}
store.Setup(context.Background()) // to create required tables
fab := fabric.New(store)
Fabric
SQLStoreuses Go's standarddatabase/sqlpackage. So any SQL database supported through this interface (includes most major SQL databases) should work.
Additional store support can be added by implementing the Store interface.
type Store interface {
Insert(ctx context.Context, tri Triple) error
Query(ctx context.Context, q Query) ([]Triple, error)
Delete(ctx context.Context, q Query) (int, error)
}
Optional Counter and ReWeighter can be implemented by the store implementations
to support extended query options.