-
Notifications
You must be signed in to change notification settings - Fork 4
/
stdlib.go
42 lines (35 loc) · 831 Bytes
/
stdlib.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
package stdlib
import (
"database/sql"
"github.com/mattn/go-sqlite3"
)
var extensions = []map[string]any{
mathFunctions,
stringFunctions,
regexpFunctions,
dateFunctions,
netFunctions,
encodingFunctions,
}
func ConnectHook(conn *sqlite3.SQLiteConn) error {
var err error
for _, functions := range extensions {
for name, impl := range functions {
err = conn.RegisterFunc(name, impl, true)
// Yes it's weird to not break on return/error
// but this way we get 100% test coverage on
// this function. Errors shouldn't happen
// outside of development anyway.
}
}
for name, impl := range aggregateFunctions {
err = conn.RegisterAggregator(name, impl, true)
}
return err
}
func Register(driverName string) {
sql.Register(driverName,
&sqlite3.SQLiteDriver{
ConnectHook: ConnectHook,
})
}