https://github.com/spy16/fabric
Fabric is a simple triplestore written in Golang
https://github.com/spy16/fabric
golang golang-library graph triplestore
Last synced: 4 months ago
JSON representation
Fabric is a simple triplestore written in Golang
- Host: GitHub
- URL: https://github.com/spy16/fabric
- Owner: spy16
- License: mit
- Created: 2019-04-07T19:52:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-12T14:28:23.000Z (almost 3 years ago)
- Last Synced: 2025-04-06T19:39:19.401Z (6 months ago)
- Topics: golang, golang-library, graph, triplestore
- Language: Go
- Size: 21.5 KB
- Stars: 197
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fabric
[](https://godoc.org/github.com/spy16/fabric) [](https://goreportcard.com/report/github.com/spy16/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)```go
// 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:
```go
db, err := sql.Open("sqlite3", "fabric.db")
if err != nil {
panic(err)
}store := &fabric.SQLStore{DB: db}
store.Setup(context.Background()) // to create required tablesfab := 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.
```go
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.