sqlite

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: BSD-3-Clause Imports: 5 Imported by: 1

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/rotationalio/ensign/pkg/utils/sqlite

Then you can use sql.Open in the same way you would with sqlite3:

sql.Open("ensign_sqlite3", "path/to/database.db")

Index

Constants

View Source
const (
	DriverName = "ensign_sqlite3"
)

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

Variables

This section is empty.

Functions

func NumConns

func NumConns() int

For testing purposes, returns the number of active connections.

Types

type Conn

type Conn struct {
	*sqlite3.SQLiteConn
	// contains filtered or unexported fields
}

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)

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

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