forked from uptrace/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqliteshim.go
45 lines (37 loc) · 1.27 KB
/
sqliteshim.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
// Package sqliteshim is a shim package that imports an appropriate sqlite
// driver for the build target and registers it under ShimName.
//
// Currently it uses packages in the following order:
// • modernc.org/sqlite on supported platforms,
// • github.com/mattn/go-sqlite3 if Cgo is enabled,
// Otherwise registers a driver that returns an error on unsupported platforms.
//
package sqliteshim
import (
"database/sql"
"database/sql/driver"
)
func init() {
sql.Register(ShimName, shimDriver)
}
// ShimName is the name of the shim database/sql driver registration.
const ShimName = "sqliteshim"
// UnsupportedError is returned from driver on unsupported platforms.
type UnsupportedError struct{}
func (e *UnsupportedError) Error() string {
return "sqlite driver is not available on the current platform"
}
// HasDriver indicates that SQLite driver implementation is available.
func HasDriver() bool {
return hasDriver
}
// Driver returns the shim driver registered under ShimName name.
func Driver() driver.Driver {
return shimDriver
}
// DriverName is the name of the database/sql driver. Note that unlike ShimName
// the value depends on the build target. That is, DriverName returns the name
// of the underlying database driver.
func DriverName() string {
return driverName
}