Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotMatchDestination is an error that indicates not matching destination to scan. ErrNotMatchDestination = errors.New("not matching destination to scan") // ErrNotReadableValue is an error that indicates value is not addressable or interfaceable. ErrNotReadableValue = errors.New("value not addressable or interfaceable") // ErrNotSettable is an error that indicates the passed in variable is not settable. ErrNotSettable = errors.New("passed in variable is not settable") // ErrUnsupportedValueType is an error that indicates unsupported unmarshal type. ErrUnsupportedValueType = errors.New("unsupported unmarshal type") )
var ErrNotFound = sql.ErrNoRows
ErrNotFound is an alias of sql.ErrNoRows
Functions ¶
func SetSlowThreshold ¶ added in v1.2.3
SetSlowThreshold sets the slow threshold.
Types ¶
type BulkInserter ¶
type BulkInserter struct {
// contains filtered or unexported fields
}
A BulkInserter is used to batch insert records. Postgresql is not supported yet, because of the sql is formated with symbol `$`.
func NewBulkInserter ¶
func NewBulkInserter(sqlConn SqlConn, stmt string) (*BulkInserter, error)
NewBulkInserter returns a BulkInserter.
func (*BulkInserter) Insert ¶
func (bi *BulkInserter) Insert(args ...interface{}) error
Insert inserts given args.
func (*BulkInserter) SetResultHandler ¶
func (bi *BulkInserter) SetResultHandler(handler ResultHandler)
SetResultHandler sets the given handler.
func (*BulkInserter) UpdateOrDelete ¶
func (bi *BulkInserter) UpdateOrDelete(fn func())
UpdateOrDelete runs update or delete queries, which flushes pending records first.
func (*BulkInserter) UpdateStmt ¶
func (bi *BulkInserter) UpdateStmt(stmt string) error
UpdateStmt updates the insert statement.
type ResultHandler ¶
ResultHandler defines the method of result handlers.
type Session ¶
type Session interface { Exec(query string, args ...interface{}) (sql.Result, error) Prepare(query string) (StmtSession, error) QueryRow(v interface{}, query string, args ...interface{}) error QueryRowPartial(v interface{}, query string, args ...interface{}) error QueryRows(v interface{}, query string, args ...interface{}) error QueryRowsPartial(v interface{}, query string, args ...interface{}) error }
Session stands for raw connections or transaction sessions
func NewSessionFromTx ¶ added in v1.2.3
NewSessionFromTx returns a Session with the given sql.Tx. Use it with caution, it's provided for other ORM to interact with.
type SqlConn ¶
type SqlConn interface { Session // RawDB is for other ORM to operate with, use it with caution. // Notice: don't close it. RawDB() (*sql.DB, error) Transact(func(session Session) error) error }
SqlConn only stands for raw connections, so Transact method can be called.
func NewSqlConn ¶
NewSqlConn returns a SqlConn with given driver name and datasource.
type SqlOption ¶
type SqlOption func(*commonSqlConn)
SqlOption defines the method to customize a sql connection.
type StmtSession ¶
type StmtSession interface { Close() error Exec(args ...interface{}) (sql.Result, error) QueryRow(v interface{}, args ...interface{}) error QueryRowPartial(v interface{}, args ...interface{}) error QueryRows(v interface{}, args ...interface{}) error QueryRowsPartial(v interface{}, args ...interface{}) error }
StmtSession interface represents a session that can be used to execute statements.