qbdb

package
v2.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	QueryTarget
	DB *sql.DB
}

DB wraps sql.DB to support qb queries

func New

func New(driver qb.Driver, db *sql.DB) *DB

New returns a new DB

func (*DB) Begin

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

Begin starts a transaction

func (*DB) MustBegin

func (db *DB) MustBegin() Tx

MustBegin is the same as Begin, but it panics if an error occurred

type Driver

type Driver struct{}

Driver is a default driver used for tests

func (Driver) BoolString

func (d Driver) BoolString(v bool) string

BoolString returns the notation for boolean values

func (Driver) Limit

func (d Driver) Limit(sql qb.SQL, limit int)

Limit implements qb.Driver

func (Driver) Override

func (d Driver) Override() qb.OverrideMap

Override returns the override map

func (Driver) Returning

func (d Driver) Returning(b qb.SQLBuilder, q qb.Query, f []qb.Field) (string, []interface{})

Returning implements qb.Driver

func (Driver) TypeName

func (d Driver) TypeName(t qb.DataType) string

TypeName returns the sql name for a type

func (Driver) UpsertSQL

func (d Driver) UpsertSQL(_ *qb.Table, _ []qb.Field, _ qb.Query) (string, []interface{})

UpsertSQL implements qb.Driver

func (Driver) ValueString

func (d Driver) ValueString(c int) string

ValueString returns the placeholder for prepare values

type QueryTarget

type QueryTarget struct {
	Driver qb.Driver
	Debug  bool
	// contains filtered or unexported fields
}

QueryTarget is a sql.DB or sql.Tx

func (QueryTarget) Exec

func (db QueryTarget) Exec(q qb.Query) (sql.Result, error)

Exec executes the given query, returns only an error

func (QueryTarget) Prepare

func (db QueryTarget) Prepare(q qb.Query) (*Stmt, error)

Prepare prepares a query for efficient repeated executions

func (QueryTarget) Query

func (db QueryTarget) Query(q qb.SelectQuery) (*sql.Rows, error)

Query executes the given SelectQuery on the database

func (QueryTarget) QueryRow

func (db QueryTarget) QueryRow(q qb.SelectQuery) *sql.Row

QueryRow executes the given SelectQuery on the database, only returns one row

func (QueryTarget) RawExec

func (db QueryTarget) RawExec(s string, v ...interface{}) (sql.Result, error)

RawExec executes the given SQL with the given params directly on the database

func (QueryTarget) Render

func (db QueryTarget) Render(q qb.Query) (string, []interface{})

Render returns the generated SQL and values without executing the query

type Stmt

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

Stmt represents a prepared statement in the database

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes the prepared statement

func (*Stmt) Exec

func (s *Stmt) Exec() error

Exec executes the given query, returns only an error

func (*Stmt) Query

func (s *Stmt) Query() (*sql.Rows, error)

Query executes the given SelectQuery on the database

func (*Stmt) QueryRow

func (s *Stmt) QueryRow() *sql.Row

QueryRow executes the given SelectQuery on the database, only returns one row

type Tx

type Tx struct {
	QueryTarget
	// contains filtered or unexported fields
}

Tx is a transaction

func (Tx) Commit

func (t Tx) Commit() error

Commit applies all the changes from the transaction

func (Tx) MustCommit

func (t Tx) MustCommit()

MustCommit is the same as Commit, but it panics if an error occurred

func (Tx) Rollback

func (t Tx) Rollback() error

Rollback reverts all the changes from the transaction

Jump to

Keyboard shortcuts

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