qbdb

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 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) IgnoreConflictSQL

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

IgnoreConflictSQL implements qb.Driver

func (Driver) LimitOffset

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

LimitOffset 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) (Result, error)

Exec executes the given query, returns only an error

func (QueryTarget) MustExec

func (db QueryTarget) MustExec(q qb.Query) Result

MustExec executes the given query If an error occurs returned it will panic

func (QueryTarget) MustPrepare

func (db QueryTarget) MustPrepare(q qb.Query) *Stmt

MustPrepare prepares a query for efficient repeated executions If an error occurs returned it will panic

func (QueryTarget) MustQuery

func (db QueryTarget) MustQuery(q qb.SelectQuery) Rows

MustQuery executes the given SelectQuery on the database If an error occurs returned it will panic

func (QueryTarget) MustRawExec

func (db QueryTarget) MustRawExec(s string, v ...interface{}) Result

MustRawExec executes the given SQL with the given params directly on the database If an error occurs returned it will panic

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) (Rows, error)

Query executes the given SelectQuery on the database

func (QueryTarget) QueryRow

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

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

func (QueryTarget) RawExec

func (db QueryTarget) RawExec(s string, v ...interface{}) (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 Result

type Result struct {
	sql.Result
}

Result is a wrapper for sql.Result that adds MustLastInsertId and MustRowsAffected

func (Result) MustLastInsertId

func (r Result) MustLastInsertId() int64

MustLastInsertId is the same as LastInsertId except if an error occurs returned it will panic

func (Result) MustRowsAffected

func (r Result) MustRowsAffected() int64

MustRowsAffected is the same as RowsAffected except if an error occurs returned it will panic

type Row

type Row struct {
	*sql.Row
}

Row is a wrapper for sql.Row that adds MustScan

func (Row) MustScan

func (r Row) MustScan(dest ...interface{}) bool

MustScan returns true if there was a row. / If an error occurs it will panic

type Rows

type Rows struct {
	*sql.Rows
}

Rows is a wrapper for sql.Rows that adds MustScan

func (Rows) MustScan

func (r Rows) MustScan(dest ...interface{})

MustScan is the same as Scan except if an error occurs returned it will panic

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() (Result, error)

Exec executes the prepared statement

func (*Stmt) MustExec

func (s *Stmt) MustExec() Result

MustExec executes the given SelectQuery on the database

func (*Stmt) MustQuery

func (s *Stmt) MustQuery() Rows

MustQuery executes the prepared statement on the database

func (*Stmt) Query

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

Query executes the prepared statement on the database

func (*Stmt) QueryRow

func (s *Stmt) QueryRow() Row

QueryRow executes the prepared statement on the database, only returns one row

type Target

type Target interface {
	Render(qb.Query) (string, []interface{})
	Query(qb.SelectQuery) (Rows, error)
	MustQuery(qb.SelectQuery) Rows
	QueryRow(qb.SelectQuery) Row
	Exec(q qb.Query) (Result, error)
	MustExec(q qb.Query) Result
	RawExec(s string, v ...interface{}) (Result, error)
	MustRawExec(s string, v ...interface{}) Result
	Prepare(q qb.Query) (*Stmt, error)
	MustPrepare(q qb.Query) *Stmt
}

Target is a target for a query, either a plain DB or a Tx

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