Documentation ¶
Overview ¶
Package sqlite implements a connect hook around the sqlite3 driver so that the underlying connection can be fetched from the driver for more advanced operations such as backups. See: https://github.com/mattn/go-sqlite3/blob/master/_example/hook/hook.go. To use make sure you import this package so that the init code registers the driver: import _ github.com/datumforge/datum/pkg/utils/sqlite - Then you can use sql.Open in the same way you would with sqlite3: sql.Open("datum_sqlite3", "path/to/database.db")
Index ¶
Constants ¶
const (
DriverName = "datum_sqlite3"
)
In order to use this driver, specify the DriverName to sql.Open.
Variables ¶
var (
ErrUnknownConnectionType = errors.New("unknown connection type")
)
Error constants
Functions ¶
Types ¶
type Conn ¶
type Conn struct { *sqlite3.SQLiteConn // contains filtered or unexported fields }
Conn wraps a sqlite3.SQLiteConn and maintains an ID so that the connection can be closed
func GetLastConn ¶
GetLastConn returns the last connection created by the driver. Unfortunately, there is no way to guarantee which connection will be returned since the sql.Open package does not provide any interface to the underlying connection object. The best a process can do is ping the server to open a new connection and then fetch the last connection immediately.
func (*Conn) Backup ¶
Backup function is here to provide access to SQLite3 backup functionality on the sqlite3 connection. For more details on how to use the backup see the following links:
https://www.sqlite.org/backup.html https://github.com/mattn/go-sqlite3/blob/master/_example/hook/hook.go https://github.com/mattn/go-sqlite3/blob/master/backup_test.go
This is primarily used by the backups package and this method provides access directly to the underlying CGO call. This means the CGO call must be called correctly for example: the Finish() method MUST BE CALLED otherwise your code will panic.
type Driver ¶
type Driver struct {
sqlite3.SQLiteDriver
}
Driver embeds a sqlite3 driver but overrides the Open function to ensure the connection created is a local connection with a sequence ID. It then maintains the connection locally until it is closed so that the underlying sqlite3 connection can be returned on demand.