/
edgedb.go
62 lines (49 loc) · 985 Bytes
/
edgedb.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
56
57
58
59
60
61
62
package edgedb
import (
"context"
"github.com/edgedb/edgedb-go"
"github.com/spf13/viper"
)
// Config ...
type Config struct {
URI string
}
// Store implementation of db interface
type Store struct {
client *edgedb.Client
config Config
}
// Init ...
func (s *Store) Init(ctx context.Context) error {
var err error
// Set configuration
s.setConfig()
// Connect to EdgeDB
s.client, err = edgedb.CreateClientDSN(ctx, s.config.URI, edgedb.Options{
Database: "shortlink",
})
if err != nil {
return err
}
return nil
}
// GetConn ...
func (s *Store) GetConn() interface{} {
return s.client
}
// Close ...
func (s *Store) Close() error {
return s.client.Close()
}
// Migrate ...
func (s *Store) migrate() error {
return nil
}
// setConfig - set configuration
func (s *Store) setConfig() {
viper.AutomaticEnv()
viper.SetDefault("STORE_EDGEDB_URI", "edgedb://localhost:5656") // EdgeDB URI
s.config = Config{
URI: viper.GetString("STORE_EDGEDB_URI"),
}
}