-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.go
More file actions
49 lines (40 loc) · 1.73 KB
/
package.go
File metadata and controls
49 lines (40 loc) · 1.73 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package stable
// STable represents simple string table engine.
// All rows are stored as a map[string]string.
// Primary key and constraints are supported.
// Triggers are supported.
//
// It is safe calling STable methods from concurrently running goroutines.
type STable interface {
// Insert inserts rows with constraints checks.
Insert(rows []map[string]string) (int, error)
// Insert inserts or updates rows (based on primary key) with constraints checks.
// Fields of updated rows will be merged instead of row to be fully replaced.
Upsert(rows []map[string]string) (int, error)
// Update updates rows based on conditions with constraints checks.
// Primary key if forbidden to update (you may use delete + insert).
Update(fields map[string]string, where map[string]string) (int, error)
// Delete deletes rows by conditions.
Delete(where map[string]string) (int, error)
// Select selects rows by conditions.
// sql.ErrNoRows will be throwed when no rows found.
Select(where map[string]string) (rows []map[string]string, err error)
// SelectAny selects one random row by conditions.
// sql.ErrNoRows will be throwed when no rows found.
SelectAny(where map[string]string) (row map[string]string, err error)
// AddTrigger adds trigger to STable.
AddTrigger(trigger Trigger)
}
const (
// OperationInsert represents insert event constant for a Trigger.
OperationInsert = iota
// OperationUpdate represents update event constant for a Trigger.
OperationUpdate
// OperationDelete represents delete event constant for a Trigger.
OperationDelete
)
// Trigger is a Handler called on STable events.
// Note: trigger not called when updated row is not changed.
type Trigger interface {
Handle(operation int, new, old map[string]string) error
}