sqlx

package
v0.0.0-...-c39e8e5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: AGPL-3.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Psql     = "postgres"
	Sqlite3  = "sqlite3"
	SqliteGo = "sqlite" // pure-go, transpiled from C.
)

Driver names.

Variables

This section is empty.

Functions

func DestroyTable

func DestroyTable(db *DB, t string) error

DestroyTable is a helper for destroying a table.

func DestroyTables

func DestroyTables(db *DB, ts ...string) error

DestroyTables is a helper for destroying a set of tables.

func Error

func Error(q string, err error) error

Error creates a query error if err is not nil. It returns nil if err is nil

func RunTasks

func RunTasks(db *DB, funcs ...func(db *DB) error) error

RunTasks runs a series of tasks, and returns error on the first one that fails.

Types

type DB

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

DB is a wrapper that extends the sql.DB structure.

func Open

func Open(driver, source string) (*DB, error)

Open opens a database.

func OpenPsql

func OpenPsql(source string) (*DB, error)

OpenPsql opens a postgresql database.

func OpenSqlite3

func OpenSqlite3(file string) (*DB, error)

OpenSqlite3 opens a sqlite3 database.

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin begins a transaction.

func (*DB) Driver

func (db *DB) Driver() string

Driver returns the driver name when the database is being opened.

func (DB) Q

func (w DB) Q(q string, args ...interface{}) (*sql.Rows, error)

Q queries the database with a query string.

func (DB) Q1

func (w DB) Q1(q string, args ...interface{}) *Row

Q1 executes a query string that expects one single row as the return.

func (DB) X

func (w DB) X(q string, args ...interface{}) (sql.Result, error)

X executes a query string.

type Row

type Row struct {
	Query string
	*sql.Row
}

Row is a result with the row and the query.

func (*Row) Scan

func (r *Row) Scan(dest ...interface{}) (bool, error)

Scan scans a row into values.

type Rows

type Rows struct {
	Query string
	*sql.Rows
}

Rows is a result with the rows and the query.

func (*Rows) Close

func (r *Rows) Close() error

Close closes the rows result.

func (*Rows) Err

func (r *Rows) Err() error

Err returns the error.

func (*Rows) Scan

func (r *Rows) Scan(dest ...interface{}) error

Scan scans a row into values.

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx wraps a transaction

func (Tx) Q

func (w Tx) Q(q string, args ...interface{}) (*sql.Rows, error)

Q queries the database with a query string.

func (Tx) Q1

func (w Tx) Q1(q string, args ...interface{}) *Row

Q1 executes a query string that expects one single row as the return.

func (Tx) X

func (w Tx) X(q string, args ...interface{}) (sql.Result, error)

X executes a query string.

Jump to

Keyboard shortcuts

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