Add Purge method/interface to database system

Also, implement Purger interface in bbolt storage.
This commit is contained in:
Daniel 2020-09-24 15:02:51 +02:00
parent 362539692e
commit 82af986224
5 changed files with 158 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package database
import (
"context"
"errors"
"fmt"
"time"
@ -400,6 +401,22 @@ func (i *Interface) Query(q *query.Query) (*iterator.Iterator, error) {
return db.Query(q, i.options.Local, i.options.Internal)
}
// Purge deletes all records that match the given query. It returns the number
// of successful deletes and an error.
func (i *Interface) Purge(ctx context.Context, q *query.Query) (int, error) {
_, err := q.Check()
if err != nil {
return 0, err
}
db, err := getController(q.DatabaseName())
if err != nil {
return 0, err
}
return db.Purge(ctx, 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()