core

package
v0.0.0-...-386c639 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMapPointer represents error when no map pointer
	ErrNoMapPointer = errors.New("mp should be a map's pointer")
	// ErrNoStructPointer represents error when no struct pointer
	ErrNoStructPointer = errors.New("mp should be a struct's pointer")
)
View Source
var (
	// DefaultCacheSize sets the default cache size
	DefaultCacheSize = 200
)

Functions

func MapToSlice

func MapToSlice(query string, mp interface{}) (string, []interface{}, error)

func StructToSlice

func StructToSlice(query string, st interface{}) (string, []interface{}, error)

Types

type DB

type DB struct {
	*sql.DB
	Mapper names.Mapper

	Logger log.ContextLogger
	// contains filtered or unexported fields
}

DB is a wrap of sql.DB with extra contents

func FromDB

func FromDB(db *sql.DB) *DB

FromDB creates a DB from a sql.DB

func Open

func Open(driverName, dataSourceName string) (*DB, error)

Open opens a database

func (*DB) AddHook

func (db *DB) AddHook(h ...contexts.Hook)

func (*DB) Begin

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

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*DB) ExecMap

func (db *DB) ExecMap(query string, mp interface{}) (sql.Result, error)

func (*DB) ExecMapContext

func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error)

ExecMapContext exec map with context.ContextHook insert into (name) values (?) insert into (name) values (?name)

func (*DB) ExecStruct

func (db *DB) ExecStruct(query string, st interface{}) (sql.Result, error)

func (*DB) ExecStructContext

func (db *DB) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)

func (*DB) NeedLogSQL

func (db *DB) NeedLogSQL(ctx context.Context) bool

NeedLogSQL returns true if need to log SQL

func (*DB) Prepare

func (db *DB) Prepare(query string) (*Stmt, error)

func (*DB) PrepareContext

func (db *DB) PrepareContext(ctx context.Context, query string) (*Stmt, error)

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*Rows, error)

Query overwrites sql.DB.Query

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)

QueryContext overwrites sql.DB.QueryContext

func (*DB) QueryMap

func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error)

QueryMap executes query with parameters via map

func (*DB) QueryMapContext

func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error)

QueryMapContext executes query with parameters via map and context

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) *Row

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row

func (*DB) QueryRowMap

func (db *DB) QueryRowMap(query string, mp interface{}) *Row

func (*DB) QueryRowMapContext

func (db *DB) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row

func (*DB) QueryRowStruct

func (db *DB) QueryRowStruct(query string, st interface{}) *Row

func (*DB) QueryRowStructContext

func (db *DB) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row

func (*DB) QueryStruct

func (db *DB) QueryStruct(query string, st interface{}) (*Rows, error)

func (*DB) QueryStructContext

func (db *DB) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error)

type EmptyScanner

type EmptyScanner struct {
}

func (EmptyScanner) Scan

func (EmptyScanner) Scan(src interface{}) error

type Executer

type Executer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

Executer represents an interface to execute a SQL

type NullTime

type NullTime time.Time

func (*NullTime) Scan

func (ns *NullTime) Scan(value interface{}) error

func (NullTime) Value

func (ns NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type QueryExecuter

type QueryExecuter interface {
	Queryer
	Executer
}

QueryExecuter combines the Queryer and Executer

type Queryer

type Queryer interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
}

Queryer represents an interface to query a SQL to get data from database

type Row

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

func ErrorRow

func ErrorRow(err error) *Row

ErrorRow return an error row

func NewRow

func NewRow(rows *Rows, err error) *Row

NewRow from rows

func (*Row) Columns

func (row *Row) Columns() ([]string, error)

func (*Row) Scan

func (row *Row) Scan(dest ...interface{}) error

func (*Row) ScanMap

func (row *Row) ScanMap(dest interface{}) error

scan data to a map's pointer

func (*Row) ScanSlice

func (row *Row) ScanSlice(dest interface{}) error

scan data to a slice's pointer, slice's length should equal to columns' number

func (*Row) ScanStructByIndex

func (row *Row) ScanStructByIndex(dest interface{}) error

func (*Row) ScanStructByName

func (row *Row) ScanStructByName(dest interface{}) error

func (*Row) ToMapString

func (row *Row) ToMapString() (map[string]string, error)

type Rows

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

func (*Rows) ScanMap

func (rs *Rows) ScanMap(dest interface{}) error

scan data to a map's pointer

func (*Rows) ScanSlice

func (rs *Rows) ScanSlice(dest interface{}) error

scan data to a slice's pointer, slice's length should equal to columns' number

func (*Rows) ScanStructByIndex

func (rs *Rows) ScanStructByIndex(dest ...interface{}) error

scan data to a struct's pointer according field index

func (*Rows) ScanStructByName

func (rs *Rows) ScanStructByName(dest interface{}) error

scan data to a struct's pointer according field name

func (*Rows) ToMapString

func (rs *Rows) ToMapString() ([]map[string]string, error)

type Stmt

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

Stmt reprents a stmt objects

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)

func (*Stmt) ExecMap

func (s *Stmt) ExecMap(mp interface{}) (sql.Result, error)

func (*Stmt) ExecMapContext

func (s *Stmt) ExecMapContext(ctx context.Context, mp interface{}) (sql.Result, error)

func (*Stmt) ExecStruct

func (s *Stmt) ExecStruct(st interface{}) (sql.Result, error)

func (*Stmt) ExecStructContext

func (s *Stmt) ExecStructContext(ctx context.Context, st interface{}) (sql.Result, error)

func (*Stmt) Query

func (s *Stmt) Query(args ...interface{}) (*Rows, error)

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error)

func (*Stmt) QueryMap

func (s *Stmt) QueryMap(mp interface{}) (*Rows, error)

func (*Stmt) QueryMapContext

func (s *Stmt) QueryMapContext(ctx context.Context, mp interface{}) (*Rows, error)

func (*Stmt) QueryRow

func (s *Stmt) QueryRow(args ...interface{}) *Row

func (*Stmt) QueryRowContext

func (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row

func (*Stmt) QueryRowMap

func (s *Stmt) QueryRowMap(mp interface{}) *Row

func (*Stmt) QueryRowMapContext

func (s *Stmt) QueryRowMapContext(ctx context.Context, mp interface{}) *Row

func (*Stmt) QueryRowStruct

func (s *Stmt) QueryRowStruct(st interface{}) *Row

func (*Stmt) QueryRowStructContext

func (s *Stmt) QueryRowStructContext(ctx context.Context, st interface{}) *Row

func (*Stmt) QueryStruct

func (s *Stmt) QueryStruct(st interface{}) (*Rows, error)

func (*Stmt) QueryStructContext

func (s *Stmt) QueryStructContext(ctx context.Context, st interface{}) (*Rows, error)

type Tx

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

Tx represents a transaction

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*Tx) ExecMap

func (tx *Tx) ExecMap(query string, mp interface{}) (sql.Result, error)

func (*Tx) ExecMapContext

func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error)

func (*Tx) ExecStruct

func (tx *Tx) ExecStruct(query string, st interface{}) (sql.Result, error)

func (*Tx) ExecStructContext

func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*Stmt, error)

func (*Tx) PrepareContext

func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error)

func (*Tx) Query

func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error)

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)

func (*Tx) QueryMap

func (tx *Tx) QueryMap(query string, mp interface{}) (*Rows, error)

func (*Tx) QueryMapContext

func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error)

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...interface{}) *Row

func (*Tx) QueryRowContext

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row

func (*Tx) QueryRowMap

func (tx *Tx) QueryRowMap(query string, mp interface{}) *Row

func (*Tx) QueryRowMapContext

func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row

func (*Tx) QueryRowStruct

func (tx *Tx) QueryRowStruct(query string, st interface{}) *Row

func (*Tx) QueryRowStructContext

func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row

func (*Tx) QueryStruct

func (tx *Tx) QueryStruct(query string, st interface{}) (*Rows, error)

func (*Tx) QueryStructContext

func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error)

func (*Tx) Rollback

func (tx *Tx) Rollback() error

func (*Tx) Stmt

func (tx *Tx) Stmt(stmt *Stmt) *Stmt

func (*Tx) StmtContext

func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt

Jump to

Keyboard shortcuts

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