Documentation ¶
Index ¶
- Constants
- Variables
- func Scan(target interface{}, rows *sql.Rows) error
- type DB
- func (db *DB) ActiveTX() bool
- func (db *DB) AfterCommit(f func())
- func (db *DB) AfterRollback(f func())
- func (db *DB) AfterTransaction(f func())
- func (db *DB) Begin() (*DB, error)
- func (db *DB) BeginContext(ctx context.Context, opts *sql.TxOptions) (*DB, error)
- func (db *DB) BeginRead() (*DB, error)
- func (db *DB) Close() error
- func (db *DB) Commit() error
- func (db *DB) DB() *sql.DB
- func (db *DB) Esc(s string) string
- func (db *DB) EscValue(s string) string
- func (db *DB) EscValueForInsert(value interface{}, fi *fieldInfo) string
- func (db *DB) Exec(execSql string, args ...interface{}) error
- func (db *DB) ExecContext(ctx context.Context, execSql string, args ...interface{}) error
- func (db *DB) ExecContextRowsAffected(ctx context.Context, execSql string, args ...interface{}) (int64, int64, error)
- func (db *DB) Insert(table string, data interface{}) error
- func (db *DB) InsertBulk(table string, data interface{}) error
- func (db *DB) InsertBulkContext(ctx context.Context, table string, data interface{}) error
- func (db *DB) InsertBulkCopyIn(table string, data interface{}) error
- func (db *DB) InsertContext(ctx context.Context, table string, data interface{}) error
- func (db *DB) IsClosed() bool
- func (db *DB) IsWriteMode() bool
- func (db *DB) Log() *DB
- func (db *DB) PrintQueryContext(ctx context.Context, query string, args ...interface{}) error
- func (db *DB) Query(target interface{}, query string, args ...interface{}) error
- func (db *DB) QueryContext(ctx context.Context, target interface{}, query string, args ...interface{}) error
- func (db *DB) Rollback() error
- func (db *DB) Save(table string, data interface{}) error
- func (db *DB) String() string
- func (db *DB) TX() *sql.Tx
- func (db *DB) Update(table string, data interface{}) error
- func (db *DB) UpdateBulk(table string, data interface{}) error
- func (db *DB) UpdateBulkContext(ctx context.Context, table string, data interface{}) error
- func (db *DB) UpdateContext(ctx context.Context, table string, data interface{}) error
- type DebugLevel
- type NullJson
- type NullRawMessage
- type NullTime
- type PlaceholderMode
Constants ¶
const ( PANIC DebugLevel = 1 ERROR = 2 UPDATE = 4 INSERT = 8 EXEC = 16 QUERY = 32 QUERY_DUMP = 64 )
const POSTGRES = "postgres"
The driver strings must match the driver from the stdlib
const SQLITE3 = "sqlite3"
Variables ¶
var ErrMismatchedRowsAffected error = errors.New("Mismatched rows affected.")
var ErrQueryReturnedZeroRows error = errors.New("Query returned 0 rows.")
Functions ¶
func Scan ¶
Scan reads data from the given rows into the target.
*int64, *string, etc: First column of first row *struct: First row []int64, []*int64, []string, []*string: First column, all rows []struct, []*struct: All columns, all rows
The mapping into structs is done by analyzing the struct's tag names and using the given "db" key for the mapping. The mapping works on exported fields only. Use "-" as mapping name to ignore the field.
Types ¶
type DB ¶
type DB struct { Debug bool DebugExec bool DebugQuery bool PlaceholderMode PlaceholderMode PlaceholderEscape rune PlaceholderValue rune PlaceholderKey rune MaxPlaceholder int UseReturningForLastId bool SupportsLastInsertId bool Driver dbDriver DSN string LastError error // This is set to the last error // contains filtered or unexported fields }
func New ¶
func New(dbWrap dbWrappable) *DB
NewSqlPro returns a wrapped database handle providing access to the sql pro functions.
func (*DB) AfterCommit ¶
func (db *DB) AfterCommit(f func())
func (*DB) AfterRollback ¶
func (db *DB) AfterRollback(f func())
func (*DB) AfterTransaction ¶
func (db *DB) AfterTransaction(f func())
func (*DB) BeginContext ¶
Begin starts a new transaction, (read-write mode)
func (*DB) EscValueForInsert ¶
func (*DB) ExecContext ¶
func (*DB) ExecContextRowsAffected ¶
func (db *DB) ExecContextRowsAffected(ctx context.Context, execSql string, args ...interface{}) (int64, int64, error)
ExecContextExp executes execSql in context ctx. If the number of rows affected doesn't match expRows, an error is returned.
func (*DB) InsertBulk ¶
func (*DB) InsertBulkContext ¶
InsertBulk takes a table name and a slice of struct and inserts the record in the DB with one Exec. The given data needs to be:
*[]*strcut *[]struct []*struct []struct
sqlpro will executes one INSERT statement per call.
func (*DB) InsertBulkCopyIn ¶
func (*DB) InsertContext ¶
func (*DB) IsWriteMode ¶
func (*DB) PrintQueryContext ¶
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, target interface{}, query string, args ...interface{}) error
Query runs a query and fills the received rows or row into the target. It is a wrapper method around the
func (*DB) Save ¶
Save saves the given data. It performs an INSERT if the only primary key is zero, and and UPDATE if it is not. It panics if it the record has no primary key or less than one
func (*DB) UpdateBulk ¶
func (*DB) UpdateBulkContext ¶
UpdateBulkContext updates all records of the passed slice. It using a single exec to send the data to the database. This is generally faster than calling Update with a slice (which sends individual update requests).
type DebugLevel ¶
type DebugLevel int
type NullRawMessage ¶
type NullRawMessage struct { Data json.RawMessage Valid bool }
func (*NullRawMessage) Scan ¶
func (nj *NullRawMessage) Scan(value interface{}) error