mirror of
https://github.com/safing/portbase
synced 2025-09-10 14:57:46 +00:00
Start api revamp
This commit is contained in:
parent
6bee0bf2d7
commit
b246453a83
16 changed files with 452 additions and 45 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue