unbolted

package module
v0.0.0-...-9022706 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2015 License: GPL-2.0 Imports: 12 Imported by: 0

README

unbolted

Object, query and subscription layer on top of https://github.com/boltdb/bolt

If you want to simplify storing Go struct types in boltdb, or even want to index and query them, or subscribe to changes to them, this might be for you.

Documentation

http://godoc.org/github.com/zond/unbolted

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllOps = Create | Update | Delete

AllOps is the binary OR of all the database operations you can subscribe to.

View Source
var ErrNotFound = fmt.Errorf("Not found")

Functions

This section is empty.

Types

type And

type And []QFilter

And is a QFilter that defines an AND operation.

type DB

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

DB wraps a bolt database in an object API.

func MustDB

func MustDB(path string) (result *DB)

MustDB returns a DB or panics.

func NewDB

func NewDB(path string) (result *DB, err error)

NewDB returns a DB using (or reusing) path as persistent file.

func (*DB) AfterTransaction

func (self *DB) AfterTransaction(f func(*DB) error) (err error)

AfterTransaction will append f to a list of functions that will run after the current transaction finishes. If run outside a transaction it will wait until the next transaction finishes. If f returns an error, the transaction call (Update or View) will return an error, but mutating transactions will still commit!

func (*DB) Close

func (self *DB) Close() (err error)

Close closes the database persistence file.

func (*DB) EmitUpdate

func (self *DB) EmitUpdate(obj interface{}) (err error)

EmitUpdate will artificially emit an update on obj, that will cause all subscriptions for update operations on matching objects get an update event.

func (*DB) Query

func (self *DB) Query() *Query

Query returns a new query for DB.

func (*DB) String

func (self *DB) String() string

func (*DB) Subscription

func (self *DB) Subscription(name string, obj interface{}, ops Operation, subscriber Subscriber) (result *Subscription, err error)

Subscription will return a subscription with name, watching changes to objects with the same type and id as obj. It will watch for operations matching the ops, and send the events to the subscriber.

func (*DB) Unsubscribe

func (self *DB) Unsubscribe(name string)

Unsubscribe will remove the named subscription from this DB.

func (*DB) Update

func (self *DB) Update(f func(tx *TX) error) (err error)

Update opens a read/write transaction.

func (*DB) View

func (self *DB) View(f func(tx *TX) error) (err error)

View opens a read only transaction.

type Equals

type Equals struct {
	Field string
	Value interface{}
}

Equals is a QFilter that defines an == operation.

type Id

type Id []byte

Id is what identifies objects.

func DecodeId

func DecodeId(s string) (result Id, err error)

DecodeId decodes the String() representation of an Id.

func (*Id) Equals

func (self *Id) Equals(o Id) bool

func (Id) MarshalJSON

func (self Id) MarshalJSON() (b []byte, err error)

func (Id) String

func (self Id) String() string

func (*Id) UnmarshalJSON

func (self *Id) UnmarshalJSON(b []byte) (err error)

type Logger

type Logger func(i interface{}, op Operation, dur time.Duration)

Logger is used to log and/or measure what the subscribers do.

type Operation

type Operation int

Operation defines a kind of database change.

const (
	// Create is the operation used when new objects are inserted into the database.
	Create Operation = 1 << iota
	// Update is the operation used when existing objects are updated in the database.
	Update
	// Delete is the operation used when existing objects are removed from the database.
	Delete
)

func (Operation) String

func (self Operation) String() string

type Or

type Or []QFilter

Or is a QFilter that defineds an OR operation.

type QFilter

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

QFilters are used to filter queries

type Query

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

Query is a search operation using a somewhat SQLy syntax to fetch records from the database.

Example: db.Query().Filter(And{Equals{"Name", "John"}, Or{Equals{"Surname", "Doe"}, Equals{"Surname", "Smith"}}}).All(&result)

func (*Query) All

func (self *Query) All(result interface{}) (err error)

All will load all results of this quer into result.

func (*Query) Except

func (self *Query) Except(f QFilter) *Query

Except will add a filter excluding matching items from the results of this query.

func (*Query) First

func (self *Query) First(result interface{}) (found bool, err error)

First will load the first match of this query into result.

func (*Query) Limit

func (self *Query) Limit(l int) *Query

Limit will limit the number of matches returned.

func (*Query) Subscription

func (self *Query) Subscription(name string, obj interface{}, ops Operation, subscriber Subscriber) (result *Subscription, err error)

Subscription will return a subscription with name, watching changes to objects of the same type as obj matching this query. It will watch for operations matching ops, and send the events to subscriber.

func (*Query) Where

func (self *Query) Where(f QFilter) *Query

Where will add a filter limiting the results of this query to matching items.

type Subscriber

type Subscriber func(obj interface{}, op Operation) error

Subscribers get updates when objects are updated. If the Subscriber returns an error or panics, it will be unsubscribed.

type Subscription

type Subscription struct {
	// UnsubscribeListener will be notified when this Subscription gets unsubscribed.
	UnsubscribeListener UnsubscribeListener
	// Logger gets notified whenever something happens with this Subscription.
	Logger Logger
	// contains filtered or unexported fields
}

Subscription is returned when the DB or a Query is asked to subscribe to something. It doesn't start working until Subscribe is called. Before you call Subscribe you can set an UnsubscribeListener or a Logger.

func (*Subscription) Subscribe

func (self *Subscription) Subscribe()

Subscribe will start the subscription.

func (*Subscription) Unsubscribe

func (self *Subscription) Unsubscribe(reason interface{})

Unsubscribe will unsubscribe this Subscription with the given reason.

type TX

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

func (*TX) Clear

func (self *TX) Clear() (err error)

Clear will empty this TX.

func (*TX) Count

func (self *TX) Count(obj interface{}) (result int, err error)

Count returns the number of objects of the same type as obj in this TX.

func (*TX) DB

func (self *TX) DB() *DB

DB returns the DB of this TX.

func (*TX) Del

func (self *TX) Del(obj interface{}) (err error)

Del will delete the object in this TX of the same type and id as obj.

func (*TX) Get

func (self *TX) Get(obj interface{}) error

Get will load the object in this TX of the same type and id as obj into obj.

func (*TX) Index

func (self *TX) Index(obj interface{}) (err error)

Index will to load obj in this TX, de-index it and then index it again. Indexed fields are annotated with `unbolted:"index"`.

func (*TX) Query

func (self *TX) Query() *Query

Query will return a query in this TX.

func (*TX) Set

func (self *TX) Set(obj interface{}) (err error)

Set will save obj in this TX. If obj has no Id, or if the Id does not already exist in the TX, it will be indexed and created. If obj has an Id that exists in the TX, the old object will be loaded and de-indexed, then obj will be indexd and saved. Indexed fields have the annotation `unbolted:"index"`.

type UnsubscribeListener

type UnsubscribeListener func(name string, reason interface{})

UnsubscribeListener is used to notify a user of a Subscriber that the Subscriber has been unsubscribed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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