Skip to content
/ fabric Public

Fabric is a simple triplestore written in Golang

License

Notifications You must be signed in to change notification settings

spy16/fabric

Repository files navigation

Fabric

GoDoc Go Report Card

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)

// See next snippet for using persistent SQL backend
fab := fabric.New(&fabric.InMemoryStore{})

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 SQLStore uses Go's standard database/sql package. 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.

REST API

The server package exposes REST APIs (/triples endpoint) which can be used to query, insert/delete or reweight triples using any HTTP client.

About

Fabric is a simple triplestore written in Golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published