-
Notifications
You must be signed in to change notification settings - Fork 111
/
postgres.go
57 lines (45 loc) · 1.18 KB
/
postgres.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
package postgres
import (
"github.com/jmoiron/sqlx"
"github.com/rilldata/rill/runtime/drivers"
"go.uber.org/zap"
// Load postgres driver
_ "github.com/jackc/pgx/v4/stdlib"
)
func init() {
drivers.Register("postgres", driver{})
}
type driver struct{}
func (d driver) Open(dsn string, logger *zap.Logger) (drivers.Connection, error) {
db, err := sqlx.Connect("pgx", dsn)
if err != nil {
return nil, err
}
return &connection{db: db}, nil
}
func (d driver) Drop(dsn string, logger *zap.Logger) error {
return drivers.ErrDropNotSupported
}
type connection struct {
db *sqlx.DB
}
// Close implements drivers.Connection.
func (c *connection) Close() error {
return c.db.Close()
}
// Registry implements drivers.Connection.
func (c *connection) RegistryStore() (drivers.RegistryStore, bool) {
return nil, false
}
// Catalog implements drivers.Connection.
func (c *connection) CatalogStore() (drivers.CatalogStore, bool) {
return nil, false
}
// Repo implements drivers.Connection.
func (c *connection) RepoStore() (drivers.RepoStore, bool) {
return nil, false
}
// OLAP implements drivers.Connection.
func (c *connection) OLAPStore() (drivers.OLAPStore, bool) {
return nil, false
}