sqlite3

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sqlite3 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.

Nicked from github.com/rotationalio/ensign

The reason for repeating the code is that we will add custom functions to the driver that will help in updating metrics that use Generic types.

AFAIK there is no way to register custom functions to the existing drivers.

Index

Constants

View Source
const (
	DriverName = "ceems_sqlite3"
)

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

Variables

This section is empty.

Functions

func NumConns

func NumConns() int

NumConns returns the number of active connections. Only for testing purposes.

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 creates a backup of the DB using backup API

The entire point of this package is 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 the DB connection When the connection is closed, it 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, err 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