numbersix

package module
v0.0.0-...-26b4426 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2020 License: MIT Imports: 5 Imported by: 1

README

numbersix

A sqlite based triple store, for storing information. Information.

It is being built for storing micropub data, but may be useful in other contexts. Data is stored in sqlite, with values marshaled using the encoding/json package.

Limitations

  • Values are stored as text, so don't expect After/Before to give sensible results if using on integer values.

This probably isn't super performant, but shouldn't be too terrible. Here are some really weak comparisons with a database/sql based implementation.

BenchmarkSimpleSqliteGet-4        100000             12952 ns/op             928 B/op         40 allocs/op
BenchmarkListAbout-4              100000             14636 ns/op            1264 B/op         49 allocs/op
BenchmarkSimpleSqliteSet-4        200000              8431 ns/op             160 B/op          9 allocs/op
BenchmarkSet-4                    200000             10154 ns/op             504 B/op         19 allocs/op

Documentation

Overview

Package numbersix implements a triple store.

It is build on top of sqlite and uses encoding/json to marshal values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AboutQuery

type AboutQuery struct {
	// contains filtered or unexported fields
}

func About

func About(subject string) *AboutQuery

About is a query that returns all triples with a particular subject.

func (*AboutQuery) Where

func (q *AboutQuery) Where(predicate string, value interface{}) *AboutQuery

Where adds a condition to the query so that only triples for subjects that have the predicate and value are returned.

type AllQuery

type AllQuery struct{}

func All

func All() *AllQuery

All is a query that returns all triples.

type AnyQuery

type AnyQuery interface {
	// contains filtered or unexported methods
}

AnyQuery defines conditions for triples that Any should match.

type BoundOrderedQuery

type BoundOrderedQuery struct {
	// contains filtered or unexported fields
}

func After

func After(predicate string, value interface{}) *BoundOrderedQuery

After is a query that returns triples for a subject having a triple with the predicate and a value after that provided. The returned triples will be ordered such that the subjects are ascending by the predicate's value. For example, if we had triples:

("a", "name", "John")
("a", "age", 20)
("b", "name", "Jane")
("b", "age", 24)
("c", "name", "Kevin")
("c", "age", 23)

Then a query of After("age", 22), would give us triples:

("c", "age", 23)
("c", "name", "Kevin")
("b", "age", 24)
("b", "name", "Jane")

func Before

func Before(predicate string, value interface{}) *BoundOrderedQuery

Before is like After, but the triples returned will have values less than the value given, and will be ordered descending on the predicate.

func (*BoundOrderedQuery) Limit

func (q *BoundOrderedQuery) Limit(count int) *BoundOrderedQuery

Limit adds a condition to the query so that only triples for count subjects are returned.

func (*BoundOrderedQuery) Where

func (q *BoundOrderedQuery) Where(predicate string, value interface{}) *BoundOrderedQuery

Where adds a condition to the query so that only triples for subjects that have the predicate and value are returned.

func (*BoundOrderedQuery) Without

func (q *BoundOrderedQuery) Without(predicate string) *BoundOrderedQuery

Without adds a condition to the query so that only triples for subjects that do not have the predicate are returned.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB stores triples.

func For

func For(db *sql.DB, name string) (*DB, error)

For returns a triple store wrapping the sql database table named.

func Open

func Open(path string) (*DB, error)

Open returns a new triple store DB writing to a sqlite database at the path given.

func (*DB) Any

func (d *DB) Any(query AnyQuery) (ok bool, err error)

Any returns true if there exists a triple matching the query provided.

func (*DB) Close

func (d *DB) Close() error

Close the underlying sqlite database.

func (*DB) DeletePredicate

func (d *DB) DeletePredicate(subject, predicate string) error

DeletePredicate removes all triples with the subject and predicate given. If none exist, then this does nothing.

func (*DB) DeleteSubject

func (d *DB) DeleteSubject(subject string) error

DeleteSubject removes all triples for the subject given. If none exist, then this does nothing.

func (*DB) DeleteValue

func (d *DB) DeleteValue(subject, predicate string, value interface{}) error

DeleteValue removes the triple for the (subject, predicate, value) given. If none exist, then this does nothing.

func (*DB) List

func (d *DB) List(query Query) (results []Triple, err error)

List returns all triples that match the query provided.

func (*DB) Set

func (d *DB) Set(subject, predicate string, value interface{}, more ...interface{}) error

Set the value(s) for a subject and predicate. Only unique values are stored per (subject, predicate) combination, and insertion order is not retained.

func (*DB) SetMany

func (d *DB) SetMany(subject, predicate string, values interface{}) error

SetMany is the same as Set, but takes a slice of values to set.

func (*DB) SetProperties

func (d *DB) SetProperties(subject string, properties map[string][]interface{}) error

SetProperties is the same as Set, but takes a map of predicates and values to set.

type Group

type Group struct {
	Subject    string
	Properties map[string][]interface{}
}

A Group contains all predicate-values for a subject.

func Grouped

func Grouped(triples []Triple) (groups []Group)

Grouped takes a list of triples and turns them in to groups. If the triples are not sorted by subject it will produce a Group for each set.

type OrderedQuery

type OrderedQuery struct {
	// contains filtered or unexported fields
}

func Ascending

func Ascending(on string) *OrderedQuery

func Descending

func Descending(on string) *OrderedQuery

func (*OrderedQuery) Where

func (q *OrderedQuery) Where(predicate string, value interface{}) *OrderedQuery

Where adds a condition to the query so that only triples for subjects that have the predicate and value are returned.

type Query

type Query interface {
	// contains filtered or unexported methods
}

Query defines conditions for triples that List should return.

type Triple

type Triple struct {
	Subject   string
	Predicate string
	// contains filtered or unexported fields
}

A Triple has a subject, predicate and value.

func (Triple) Value

func (t Triple) Value(v interface{}) error

Value will set the value to the pointer provided.

type WhereQuery

type WhereQuery struct {
	// contains filtered or unexported fields
}

func Begins

func Begins(predicate string, value interface{}) *WhereQuery

Begins is a query that returns all triples with a particular predicate that begins with the value.

func Where

func Where(predicate string, value interface{}) *WhereQuery

Where is a query that returns all triples with a particular predicate-value.

func (*WhereQuery) Has

func (q *WhereQuery) Has(predicate string) *WhereQuery

Has adds a condition to the query so that only triples for subjects that have the predicate (with any value) are returned.

func (*WhereQuery) Where

func (q *WhereQuery) Where(predicate string, value interface{}) *WhereQuery

Where adds a condition to the query so that only triples for subjects that have the predicate and value are returned.

func (*WhereQuery) Without

func (q *WhereQuery) Without(predicate string) *WhereQuery

Without adds a condition to the query so that only triples for subjects that do not have the predicate are returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL