forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdbms.go
41 lines (36 loc) · 1.06 KB
/
rdbms.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
package rdbms
import (
"github.com/gobuffalo/pop"
)
// ModuleStore represents a rdbms(postgres, mysql, sqlite, cockroachdb) backed storage backend.
type ModuleStore struct {
conn *pop.Connection
connectionName string // settings name from database.yml
}
// NewRDBMSStorage returns an unconnected RDBMS Module Storage
// that satisfies the Storage interface. You must call
// Connect() on the returned store before using it.
// connectionName
func NewRDBMSStorage(connectionName string) *ModuleStore {
return &ModuleStore{
connectionName: connectionName,
}
}
// NewRDBMSStorageWithConn returns a connected RDBMS Module Storage
// that satisfies the Storage interface. You must call
// Connect() on the returned store before using it.
// connectionName
func NewRDBMSStorageWithConn(connection *pop.Connection) *ModuleStore {
return &ModuleStore{
conn: connection,
}
}
// Connect creates connection to rdmbs backend.
func (r *ModuleStore) Connect() error {
c, err := pop.Connect(r.connectionName)
if err != nil {
return err
}
r.conn = c
return nil
}