Start api revamp

This commit is contained in:
Daniel 2018-09-21 16:38:18 +02:00
parent 6bee0bf2d7
commit b246453a83
16 changed files with 452 additions and 45 deletions

View file

@ -228,6 +228,11 @@ func (i *Interface) Delete(key string) error {
// Query executes the given query on the database.
func (i *Interface) Query(q *query.Query) (*iterator.Iterator, error) {
_, err := q.Check()
if err != nil {
return nil, err
}
db, err := getController(q.DatabaseName())
if err != nil {
return nil, err
@ -235,3 +240,30 @@ func (i *Interface) Query(q *query.Query) (*iterator.Iterator, error) {
return db.Query(q, i.options.Local, i.options.Internal)
}
// Subscribe subscribes to updates matching the given query.
func (i *Interface) Subscribe(q *query.Query) (*Subscription, error) {
_, err := q.Check()
if err != nil {
return nil, err
}
c, err := getController(q.DatabaseName())
if err != nil {
return nil, err
}
c.readLock.Lock()
defer c.readLock.Unlock()
c.writeLock.Lock()
defer c.writeLock.Unlock()
sub := &Subscription{
q: q,
local: i.options.Local,
internal: i.options.Internal,
Feed: make(chan record.Record, 100),
}
c.subscriptions = append(c.subscriptions, sub)
return sub, nil
}