db

package
v0.0.0-...-854fb4c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db exposes a lightweight abstraction over the SQLite code. It performs some basic mapping of lower-level types to tqlite types.

Index

Constants

This section is empty.

Variables

View Source
var DBVersion string

DBVersion is the SQLite version.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is the SQL database.

func DeserializeInMemoryWithDSN

func DeserializeInMemoryWithDSN(b []byte, dsn string) (*DB, error)

DeserializeInMemoryWithDSN loads an in-memory database with that contained in the byte slide, with the specified DSN. The byte slice must not be changed or garbage-collected until after this function returns.

func LoadInMemoryWithDSN

func LoadInMemoryWithDSN(dbPath, dsn string) (*DB, error)

LoadInMemoryWithDSN loads an in-memory database with that at the path, with the specified DSN

func Open

func Open(dbPath string) (*DB, error)

Open opens a file-based database, creating it if it does not exist.

func OpenInMemory

func OpenInMemory() (*DB, error)

OpenInMemory opens an in-memory database.

func OpenInMemoryWithDSN

func OpenInMemoryWithDSN(dsn string) (*DB, error)

OpenInMemoryWithDSN opens an in-memory database with a specific DSN.

func OpenWithDSN

func OpenWithDSN(dbPath, dsn string) (*DB, error)

OpenWithDSN opens a file-based database, creating it if it does not exist.

func (*DB) AbortTransaction

func (db *DB) AbortTransaction() error

AbortTransaction aborts -- rolls back -- any active transaction. Calling code should know exactly what it is doing if it decides to call this function. It can be used to clean up any dangling state that may result from certain error scenarios.

func (*DB) Backup

func (db *DB) Backup(path string) error

Backup writes a consistent snapshot of the database to the given file. This function can be called when changes to the database are in flight.

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying database connection.

func (*DB) Copy

func (db *DB) Copy(dstDB *DB) error

Copy copies the contents of the database to the given database. All other attributes of the given database remain untouched e.g. whether it's an on-disk database. This function can be called when changes to the source database are in flight.

func (*DB) Dump

func (db *DB) Dump(w io.Writer) error

Dump writes a consistent snapshot of the database in SQL text format. This function can be called when changes to the database are in flight.

func (*DB) EnableFKConstraints

func (db *DB) EnableFKConstraints(e bool) error

EnableFKConstraints allows control of foreign key constraint checks.

func (*DB) Execute

func (db *DB) Execute(req *command.Request, xTime bool) ([]*Result, error)

Execute executes queries that modify the database.

func (*DB) ExecuteStringStmt

func (db *DB) ExecuteStringStmt(query string) ([]*Result, error)

ExecuteStringStmt executes a single query that modifies the database. This is primarily a convenience function.

func (*DB) FKConstraints

func (db *DB) FKConstraints() (bool, error)

FKConstraints returns whether FK constraints are set or not.

func (*DB) FileSize

func (db *DB) FileSize() (int64, error)

FileSize returns the size of the SQLite file on disk. If running in on-memory mode, this function returns 0.

func (*DB) Query

func (db *DB) Query(req *command.Request, xTime bool) ([]*Rows, error)

Query executes queries that return rows, but don't modify the database.

func (*DB) QueryStringStmt

func (db *DB) QueryStringStmt(query string) ([]*Rows, error)

QueryStringStmt executes a single query that return rows, but don't modify database.

func (*DB) Serialize

func (db *DB) Serialize() ([]byte, error)

Serialize returns a byte slice representation of the SQLite database. For an ordinary on-disk database file, the serialization is just a copy of the disk file. For an in-memory database or a "TEMP" database, the serialization is the same sequence of bytes which would be written to disk if that database were backed up to disk.

It is up to the caller to ensure no changes or transactions are in progress when this function is called.

func (*DB) Size

func (db *DB) Size() (int64, error)

Size returns the size of the database in bytes. "Size" is defined as page_count * schema.page_size.

func (*DB) TransactionActive

func (db *DB) TransactionActive() bool

TransactionActive returns whether a transaction is currently active i.e. if the database is NOT in autocommit mode.

type Result

type Result struct {
	LastInsertID int64   `json:"last_insert_id,omitempty"`
	RowsAffected int64   `json:"rows_affected,omitempty"`
	Error        string  `json:"error,omitempty"`
	Time         float64 `json:"time,omitempty"`
}

Result represents the outcome of an operation that changes rows.

type Rows

type Rows struct {
	Columns []string        `json:"columns,omitempty"`
	Types   []string        `json:"types,omitempty"`
	Values  [][]interface{} `json:"values,omitempty"`
	Error   string          `json:"error,omitempty"`
	Time    float64         `json:"time,omitempty"`
}

Rows represents the outcome of an operation that returns query data.

Jump to

Keyboard shortcuts

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