-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
43 lines (35 loc) · 833 Bytes
/
db.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
package neo4j
import (
"github.com/aliworkshop/configer"
"github.com/aliworkshop/error"
"github.com/neo4j/neo4j-go-driver/neo4j"
)
type neo struct {
cfg config
db neo4j.Driver
}
func NewNeo4jRepository(configRegistry configer.Registry) Repository {
n := new(neo)
err := configRegistry.Unmarshal(&n.cfg)
if err != nil {
panic(err)
}
return n
}
func (n *neo) DB() any {
return n.db
}
func (n *neo) Connect() error.ErrorModel {
driver, err := neo4j.NewDriver(n.cfg.Address, neo4j.BasicAuth(n.cfg.Username, n.cfg.Password, ""), func(config *neo4j.Config) {
config.Encrypted = n.cfg.Tls
config.MaxConnectionPoolSize = n.cfg.MaxConnectionPoolSize
})
if err != nil {
return error.Internal(err)
}
n.db = driver
return nil
}
func (n *neo) Close() error.ErrorModel {
return error.HandleError(n.db.Close())
}