-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.go
34 lines (29 loc) · 977 Bytes
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package sparkle
import (
"context"
"errors"
)
var (
ErrNotFound = errors.New("document not found")
ErrDuplicateField = errors.New("unique field duplicate")
)
type TransactionalProvider interface {
Begin(ctx context.Context, fn func(context TransactionalContext) error) error
}
type TransactionalContext interface {
context.Context
Rollback(ctx context.Context) error
Commit(ctx context.Context) error
}
type Collection interface {
FindByID(ctx context.Context, ID string, value interface{}) error
FindOne(ctx context.Context, filter, value interface{}) error
Save(ctx context.Context, ID string, entity interface{}) error
DeleteByID(ctx context.Context, ID string) error
}
type Database interface {
FindByID(ctx context.Context, Collection, ID string, value interface{}) error
Save(ctx context.Context, Collection, ID string, entity interface{}) error
DeleteByID(ctx context.Context, Collection, ID string) error
Collection(name string) Collection
}