sqlx

package
v1.6.5-rc48 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SqlErrTypeNotFound sqlErrType = "NotFound"
	SqlErrTypeConflict sqlErrType = "Conflict"
)
View Source
var DuplicateEntryErrNumber uint16 = 1062
View Source
var ErrNotDB = errors.New("db is not *sql.DB")
View Source
var ErrNotTx = errors.New("db is not *sql.Tx")

Functions

func AsAssignments

func AsAssignments(db DBExecutor, m builder.Model, zeros ...string) builder.Assignments

func DBErr

func DBErr(err error) *dbErr

func FieldValuesFromModel

func FieldValuesFromModel(table *builder.Table, model builder.Model, zeros ...string) builder.FieldValues

func InsertToDB

func InsertToDB(db DBExecutor, m builder.Model, zeros []string, additions ...builder.Addition) builder.SqlExpr

func Scan

func Scan(ctx context.Context, rows *sql.Rows, v interface{}) error

func UnwrapAll

func UnwrapAll(err error) error

func UnwrapOnce

func UnwrapOnce(err error) (cause error)

Types

type DB

type DB struct {
	*Database
	SqlExecutor
	// contains filtered or unexported fields
}

func (*DB) Begin

func (d *DB) Begin() (DBExecutor, error)

func (*DB) BeginTx

func (d *DB) BeginTx(opt *sql.TxOptions) (DBExecutor, error)

func (*DB) Commit

func (d *DB) Commit() error

func (*DB) Context

func (d *DB) Context() context.Context

func (*DB) D

func (d *DB) D() *Database

func (*DB) Dialect

func (d *DB) Dialect() builder.Dialect

func (*DB) Exec

func (d *DB) Exec(e builder.SqlExpr) (sql.Result, error)

func (*DB) IsTx

func (d *DB) IsTx() bool

func (*DB) Migrate

func (d *DB) Migrate(ctx context.Context, db DBExecutor) error

func (*DB) Query

func (d *DB) Query(e builder.SqlExpr) (*sql.Rows, error)

func (*DB) QueryAndScan

func (d *DB) QueryAndScan(e builder.SqlExpr, v interface{}) error

func (*DB) Rollback

func (d *DB) Rollback() error

func (*DB) SetConnMaxLifetime

func (d *DB) SetConnMaxLifetime(du time.Duration)

func (*DB) SetMaxIdleConns

func (d *DB) SetMaxIdleConns(n int)

func (*DB) SetMaxOpenConns

func (d *DB) SetMaxOpenConns(n int)

func (*DB) WithContext

func (d *DB) WithContext(ctx context.Context) DBExecutor

func (DB) WithSchema

func (d DB) WithSchema(schema string) DBExecutor

type DBExecutor

type DBExecutor interface {
	ExprExecutor
	TableResolver

	Dialect() builder.Dialect
	D() *Database
	WithSchema(string) DBExecutor

	Context() context.Context
	WithContext(ctx context.Context) DBExecutor
}

type Database

type Database struct {
	Name   string
	Schema string
	Tables builder.Tables
}

func NewDatabase

func NewDatabase(name string) *Database

func (*Database) AddTable

func (d *Database) AddTable(t *builder.Table)

func (*Database) OpenDB

func (d *Database) OpenDB(connector driver.Connector) *DB

func (*Database) Register

func (d *Database) Register(m builder.Model) *builder.Table

func (*Database) T

func (d *Database) T(model builder.Model) *builder.Table

func (*Database) Table

func (d *Database) Table(name string) *builder.Table

func (Database) WithSchema

func (d Database) WithSchema(schema string) *Database

type ExprExecutor

type ExprExecutor interface {
	SqlExecutor
	Exec(builder.SqlExpr) (sql.Result, error)
	Query(builder.SqlExpr) (*sql.Rows, error)
	QueryAndScan(builder.SqlExpr, interface{}) error
}

type Migrator

type Migrator interface {
	Migrate(ctx context.Context, db DBExecutor) error
}

type ScanIterator

type ScanIterator = scanner.ScanIterator

type SqlError

type SqlError struct {
	Type sqlErrType
	Msg  string
}

func NewSqlError

func NewSqlError(tpe sqlErrType, msg string) *SqlError

func (*SqlError) Error

func (e *SqlError) Error() string

type SqlExecutor

type SqlExecutor interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

type TableResolver

type TableResolver interface {
	T(model builder.Model) *builder.Table
}

type Task

type Task func(db DBExecutor) error

func (Task) Run

func (task Task) Run(db DBExecutor) (err error)

type Tasks

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

func NewTasks

func NewTasks(db DBExecutor) *Tasks

func (*Tasks) Do

func (tasks *Tasks) Do() (err error)

func (Tasks) With

func (tasks Tasks) With(task ...Task) *Tasks

type TxExecutor

type TxExecutor interface {
	IsTx() bool
	BeginTx(*sql.TxOptions) (DBExecutor, error)
	Begin() (DBExecutor, error)
	Commit() error
	Rollback() error
}

type WithDBName

type WithDBName interface {
	WithDBName(string) driver.Connector
}

Directories

Path Synopsis
driver
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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