qbdb

package
v2.6.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 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 interface {
	Target
	Begin() (Tx, error)
	MustBegin() Tx
}

DB is a database connection

func New

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

New returns a new DB

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) EscapeCharacter

func (d Driver) EscapeCharacter() string

EscapeCharacter returns the character to escape table and field names

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 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)
	RawQuery(string, ...interface{}) (Rows, error)
	MustQuery(qb.SelectQuery) Rows
	MustRawQuery(string, ...interface{}) Rows

	QueryRow(qb.SelectQuery) Row
	RawQueryRow(string, ...interface{}) Row

	Exec(q qb.Query) (Result, error)
	RawExec(string, ...interface{}) (Result, error)
	MustExec(q qb.Query) Result
	MustRawExec(string, ...interface{}) Result

	Prepare(qb.Query) (*Stmt, error)
	MustPrepare(qb.Query) *Stmt

	Driver() qb.Driver
	SetDebug(bool)
}

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

type Tx

type Tx interface {
	Target
	Commit() error
	MustCommit()
	Rollback() error
}

Tx is a transaction

Jump to

Keyboard shortcuts

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