-
Notifications
You must be signed in to change notification settings - Fork 111
/
sqlite.go
70 lines (56 loc) · 1.48 KB
/
sqlite.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
63
64
65
66
67
68
69
70
package sqlite
import (
"strings"
"github.com/jmoiron/sqlx"
"github.com/rilldata/rill/runtime/drivers"
"go.uber.org/zap"
// Load sqlite driver
_ "modernc.org/sqlite"
)
func init() {
drivers.Register("sqlite", driver{})
}
type driver struct{}
func (d driver) Open(dsn string, logger *zap.Logger) (drivers.Connection, error) {
// The sqlite driver requires the DSN to contain "_time_format=sqlite" to support TIMESTAMP types in all timezones.
if !strings.Contains(dsn, "_time_format") {
if strings.Contains(dsn, "?") {
dsn += "&_time_format=sqlite"
} else {
dsn += "?_time_format=sqlite"
}
}
// Open DB handle
db, err := sqlx.Connect("sqlite", dsn)
if err != nil {
return nil, err
}
db.SetMaxOpenConns(1)
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 c, true
}
// Catalog implements drivers.Connection.
func (c *connection) CatalogStore() (drivers.CatalogStore, bool) {
return c, true
}
// 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
}