-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
table.go
55 lines (48 loc) · 1.09 KB
/
table.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ds
import (
"reflect"
"sync"
"github.com/ecnepsnai/logtic"
"go.etcd.io/bbolt"
)
// Table describes a ds table. A table is mapped to a single registered object type and contains
// both the data and the indexes.
type Table struct {
Name string
typeOf reflect.Type
log *logtic.Source
primaryKey string
indexes []string
uniques []string
data *bbolt.DB
options Options
lock *sync.RWMutex
}
// Close will close the table. This will not panic if the table has not been opened or already been closed.
func (table *Table) Close() {
if table != nil && table.data != nil {
go tryCloseData(table.data)
}
}
func tryCloseData(data *bbolt.DB) {
defer panicRecovery()
data.Close()
}
// IsIndexed is the given field indexed
func (table *Table) IsIndexed(field string) bool {
for _, index := range table.indexes {
if index == field {
return true
}
}
return false
}
// IsUnique is the given field unique
func (table *Table) IsUnique(field string) bool {
for _, unique := range table.uniques {
if unique == field {
return true
}
}
return false
}