8000 GitHub - hg-books/fabric: Fabric is a simple triplestore written in Golang
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hg-books/fabric

 
 

Repository files navigation

WIP

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)

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 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.

About

Fabric is a simple triplestore written in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.5%
  • Makefile 1.5%
0