-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.go
52 lines (42 loc) · 937 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gorf
import "errors"
type DbOperationType int
const (
CREATE DbOperationType = iota
GET
UPDATE
DELETE
)
type Query interface {
Describe() (string, error)
Operation() DbOperationType
}
type QuerySet interface {
Count() (int, error)
First() (any, error)
Last() (any, error)
}
type Db interface {
Get(dest interface{}, key string) error
Filter(dest interface{}, conds ...interface{}) error
AutoMigrate(dst ...interface{}) error
First(dest interface{}, conds ...interface{}) error
Create(value interface{}) error
GetUser(dest interface{}, id string) error
}
type DbBackend interface {
Connect() (Db, error)
Disconnect() error
}
var DB Db
func InitializeDatabase() error {
var err error
if Settings.DbBackends == nil {
return errors.New("no database backend present")
}
DB, err = Settings.DbBackends.Connect()
if err != nil {
return errors.New("unable to initialise the database")
}
return nil
}