db

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2019 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package db defines database utility functions.

These functions currently work on a sqlite database. Other databases may not work with functions in this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(fn func() error) (err error)

Retry executes a function repeatedly as long as it returns an error that indicates database contention that warrants a retry.

func URI

func URI(filename string, readOnly bool, memory bool) string

URI returns the sqlite URI given a db filename as an input.

Types

type Accessor

type Accessor struct {
	Handle *sql.DB
	// contains filtered or unexported fields
}

An Accessor manages a sqlite database handle and any outstanding batching operations.

func MakeAccessor

func MakeAccessor(dbfilename string, readOnly bool, inMemory bool) (Accessor, error)

MakeAccessor creates a new Accessor.

func MakeErasableAccessor

func MakeErasableAccessor(dbfilename string) (Accessor, error)

MakeErasableAccessor creates a new Accessor with the secure_delete pragma set; see https://www.sqlite.org/pragma.html#pragma_secure_delete It is not read-only and not in-memory (otherwise, erasability doesn't matter)

func (Accessor) Atomic

func (db Accessor) Atomic(fn idemFn, extras ...interface{}) (err error)

Atomic executes a piece of code with respect to the database atomically. For transactions where readOnly is false, sync determines whether or not to wait for the result.

func (Accessor) Close

func (db Accessor) Close()

Close closes the connection.

type Queryable

type Queryable interface {
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Queryable is meant to represent the union of a transaction (sql.Tx) and the underlying database (sql.DB), so that code issuing a single read-only query can be run directly on the sql.DB object without creating a short-lived transaction for a single SELECT query.

Queryable captures only a subset of Go's SQL API for issuing reads; if new code needs additional methods to query a SQL DB, they should be added here as needed.

Jump to

Keyboard shortcuts

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