sqldb

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 4 Imported by: 0

README

go-sqldb

Golang Sqlite3 Database API with automatic patch upgrading.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PatchFuncType

type PatchFuncType struct {
	// PatchID is not necessarily sequential. It just needs to be unique, but convention is sequential.
	PatchID int
	// PatchFunc will perform patch operations on the database.
	PatchFunc func(sdb *SQLDb) error
}

PatchFuncType contains unique patch ID and a patch function to run.

type SQLDb

type SQLDb struct {
	*sql.DB
}

SQLDb - SQL Database wrapper with extended patching functions.

func OpenAndPatchDb

func OpenAndPatchDb(dbFilename string, patchFuncs []PatchFuncType) (*SQLDb, error)

OpenAndPatchDb - Open and Patch a database if necessary.

func OpenDb

func OpenDb(dbFilename string) (*SQLDb, error)

OpenDb - Open a database.

func (*SQLDb) BeginTrans

func (sdb *SQLDb) BeginTrans() error

BeginTrans - Begin transaction

func (*SQLDb) CommitOnNoError

func (sdb *SQLDb) CommitOnNoError(err error) error

CommitOnNoError - Commit the transaction if the error is nil

func (*SQLDb) CommitOnSuccess

func (sdb *SQLDb) CommitOnSuccess(success bool) error

CommitOnSuccess - Commit the transaction if the expression evaluates to true.

func (*SQLDb) CommitSavePoint

func (sdb *SQLDb) CommitSavePoint(name string) error

CommitSavePoint - Commit up to the named save point, which rolls it up into parent transaction.

func (*SQLDb) CommitSavePointOnNoError

func (sdb *SQLDb) CommitSavePointOnNoError(name string, err error) error

CommitSavePointOnNoError - Commit up to the save point (or merge with parent transaction) if the error is nil.

func (*SQLDb) CommitSavePointOnSuccess

func (sdb *SQLDb) CommitSavePointOnSuccess(name string, success bool) error

CommitSavePointOnSuccess - Commit up to the save point (or merge with parent transaction) if the expression evaluates to true.

func (*SQLDb) CommitTrans

func (sdb *SQLDb) CommitTrans() error

CommitTrans - Commit transaction

func (*SQLDb) CreateIndex

func (sdb *SQLDb) CreateIndex(indexDef string) error

CreateIndex - Create the index definition.

func (*SQLDb) CreateSavePoint

func (sdb *SQLDb) CreateSavePoint(name string) error

CreateSavePoint - Create a save point for rollback or commit.

func (*SQLDb) CreateTable

func (sdb *SQLDb) CreateTable(tableDef string) error

CreateTable - Create the table definition.

func (*SQLDb) DropTable

func (sdb *SQLDb) DropTable(tableDef string) error

DropTable - Drop the table definition.

func (*SQLDb) Exec

func (sdb *SQLDb) Exec(stmt string, args ...interface{}) error

Exec - Execute the statement with the bound arguments.

func (*SQLDb) ExecResults

func (sdb *SQLDb) ExecResults(stmt string, args ...interface{}) (sql.Result, error)

ExecResults - Execute the statement with the bound arguments.

func (*SQLDb) ExecWithSavePoint added in v1.0.2

func (sdb *SQLDb) ExecWithSavePoint(spName string, fn func() error) error

ExecWithSavePoint - Execute the database function wrapped inside of a named Save Point.

func (*SQLDb) GetGkey

func (sdb *SQLDb) GetGkey() (int, error)

GetGkey - Get a gkey to be used as unique record ID

func (*SQLDb) MultiQuery

func (sdb *SQLDb) MultiQuery(stmt string, action func(rows *sql.Rows) error) error

MultiQuery - Execute a function on the returned query rows.

func (*SQLDb) PatchDb

func (sdb *SQLDb) PatchDb(patchFuncs []PatchFuncType) error

PatchDb - Patch a database if necessary.

func (*SQLDb) RollbackSavePoint

func (sdb *SQLDb) RollbackSavePoint(name string) error

RollbackSavePoint - Rollback a save point

func (*SQLDb) RollbackTrans

func (sdb *SQLDb) RollbackTrans() error

RollbackTrans - Rollback transaction

func (*SQLDb) SingleQuery

func (sdb *SQLDb) SingleQuery(stmt string, args ...interface{}) error

SingleQuery - Query the database, and retrieve the results. Expected single value return.

Jump to

Keyboard shortcuts

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