sqlite

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
const (
	DriverName = "datum_sqlite3"
)

In order to use this driver, specify the DriverName to sql.Open.

Variables

View Source
var (
	ErrUnknownConnectionType = errors.New("unknown connection type")
)

Error constants

Functions

func NumConns

func NumConns() int

NumConns is for testing purposes, returns the number of active connections

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

func GetLastConn() (*Conn, bool)

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

func (c *Conn) Backup(dest string, srcConn *Conn, src string) (*sqlite3.SQLiteBackup, error)

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.

func (*Conn) Close

func (c *Conn) Close() error

Close executes when the connection is closed so the connection is removed from the array of connections

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.

func (*Driver) Open

func (d *Driver) Open(dsn string) (driver.Conn, error)

Open implements the sql.Driver interface and returns a sqlite3 connection that can be fetched by the user using GetLastConn. The connection ensures it's cleaned up when it's closed. This method is not used by the user, but rather by sql.Open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL