Documentation ¶
Index ¶
- Variables
- type And
- type DB
- func (self *DB) AfterTransaction(f func(*DB) error) (err error)
- func (self *DB) Close() (err error)
- func (self *DB) EmitUpdate(obj interface{}) (err error)
- func (self *DB) Query() *Query
- func (self *DB) String() string
- func (self *DB) Subscription(name string, obj interface{}, ops Operation, subscriber Subscriber) (result *Subscription, err error)
- func (self *DB) Unsubscribe(name string)
- func (self *DB) Update(f func(tx *TX) error) (err error)
- func (self *DB) View(f func(tx *TX) error) (err error)
- type Equals
- type Id
- type Logger
- type Operation
- type Or
- type QFilter
- type Query
- func (self *Query) All(result interface{}) (err error)
- func (self *Query) Except(f QFilter) *Query
- func (self *Query) First(result interface{}) (found bool, err error)
- func (self *Query) Limit(l int) *Query
- func (self *Query) Subscription(name string, obj interface{}, ops Operation, subscriber Subscriber) (result *Subscription, err error)
- func (self *Query) Where(f QFilter) *Query
- type Subscriber
- type Subscription
- type TX
- func (self *TX) Clear() (err error)
- func (self *TX) Count(obj interface{}) (result int, err error)
- func (self *TX) DB() *DB
- func (self *TX) Del(obj interface{}) (err error)
- func (self *TX) Get(obj interface{}) error
- func (self *TX) Index(obj interface{}) (err error)
- func (self *TX) Query() *Query
- func (self *TX) Set(obj interface{}) (err error)
- type UnsubscribeListener
Constants ¶
This section is empty.
Variables ¶
var AllOps = Create | Update | Delete
AllOps is the binary OR of all the database operations you can subscribe to.
var ErrNotFound = fmt.Errorf("Not found")
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps a bolt database in an object API.
func (*DB) AfterTransaction ¶
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) EmitUpdate ¶
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) 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 ¶
Unsubscribe will remove the named subscription from this DB.
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 (Id) MarshalJSON ¶
func (*Id) UnmarshalJSON ¶
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 )
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) Except ¶
Except will add a filter excluding matching items from the results of this query.
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.
type Subscriber ¶
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) Index ¶
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) Set ¶
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.