Documentation ¶
Index ¶
- Constants
- Variables
- func BindDriver(driverName string, bindType int)
- func BindNamed(bindType int, query string, arg interface{}) (string, []interface{}, error)
- func BindType(driverName string) int
- func Get(q IQuery, dest interface{}, query string, args ...interface{}) error
- func GetContext(ctx context.Context, q IQueryContext, dest interface{}, query string, ...) error
- func In(query string, args ...interface{}) (string, []interface{}, error)
- func LoadFile(e IExecute, path string) (*sql.Result, error)
- func LoadFileContext(ctx context.Context, e IExecuteContext, path string) (*sql.Result, error)
- func MapScan(r ColScanner, dest map[string]interface{}) error
- func MustExec(e IExecute, query string, args ...interface{}) sql.Result
- func MustExecContext(ctx context.Context, e IExecuteContext, query string, args ...interface{}) sql.Result
- func Named(query string, arg interface{}) (string, []interface{}, error)
- func NamedExec(e Ext, query string, arg interface{}) (sql.Result, error)
- func NamedExecContext(ctx context.Context, e ExtContext, query string, arg interface{}) (sql.Result, error)
- func Rebind(bindType int, query string) string
- func Select(q IQuery, dest interface{}, query string, args ...interface{}) error
- func SelectContext(ctx context.Context, q IQueryContext, dest interface{}, query string, ...) error
- func SliceScan(r ColScanner) ([]interface{}, error)
- func StructScan(rows IRow, dest interface{}) error
- type ColScanner
- type Conn
- func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (c *Conn) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (c *Conn) PrepareXContext(ctx context.Context, query string) (*Stmt, error)
- func (c *Conn) QueryRowXContext(ctx context.Context, query string, args ...interface{}) *Row
- func (c *Conn) QueryXContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (c *Conn) Rebind(query string) string
- func (c *Conn) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- type DB
- func Connect(driverName, dataSourceName string) (*DB, error)
- func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error)
- func MustConnect(driverName, dataSourceName string) *DB
- func MustOpen(driverName, dataSourceName string) *DB
- func NewDb(db *sql.DB, driverName string) *DB
- func Open(driverName, dataSourceName string) (*DB, error)
- func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) BeginX() (*Tx, error)
- func (db *DB) BindNamed(query string, arg interface{}) (string, []interface{}, error)
- func (db *DB) ConnX(ctx context.Context) (*Conn, error)
- func (db *DB) DriverName() string
- func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (db *DB) MapperFunc(mf func(string) string)
- func (db *DB) MustBegin() *Tx
- func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx
- func (db *DB) MustExec(query string, args ...interface{}) sql.Result
- func (db *DB) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
- func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error)
- func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
- func (db *DB) NamedQuery(query string, arg interface{}) (*Rows, error)
- func (db *DB) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error)
- func (db *DB) PrepareNamed(query string) (*NamedStmt, error)
- func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)
- func (db *DB) PrepareX(query string) (*Stmt, error)
- func (db *DB) PrepareXContext(ctx context.Context, query string) (*Stmt, error)
- func (db *DB) QueryRowX(query string, args ...interface{}) *Row
- func (db *DB) QueryRowXContext(ctx context.Context, query string, args ...interface{}) *Row
- func (db *DB) QueryX(query string, args ...interface{}) (*Rows, error)
- func (db *DB) QueryXContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (db *DB) Rebind(query string) string
- func (db *DB) Select(dest interface{}, query string, args ...interface{}) error
- func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (db *DB) Take(dest interface{}, query string, args ...interface{}) error
- func (db *DB) Unsafe() *DB
- type Ext
- type ExtContext
- type IBind
- type IExecute
- type IExecuteContext
- type IPrepare
- type IPrepareContext
- type IQuery
- type IQueryContext
- type IRow
- type NamedStmt
- func (n *NamedStmt) Close() error
- func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error)
- func (n *NamedStmt) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error)
- func (n *NamedStmt) Get(dest interface{}, arg interface{}) error
- func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error
- func (n *NamedStmt) MustExec(arg interface{}) sql.Result
- func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result
- func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error)
- func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error)
- func (n *NamedStmt) QueryRow(arg interface{}) *Row
- func (n *NamedStmt) QueryRowContext(ctx context.Context, arg interface{}) *Row
- func (n *NamedStmt) QueryRowX(arg interface{}) *Row
- func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg interface{}) *Row
- func (n *NamedStmt) QueryX(arg interface{}) (*Rows, error)
- func (n *NamedStmt) QueryxContext(ctx context.Context, arg interface{}) (*Rows, error)
- func (n *NamedStmt) Select(dest interface{}, arg interface{}) error
- func (n *NamedStmt) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error
- func (n *NamedStmt) Unsafe() *NamedStmt
- type Row
- func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Row) Columns() ([]string, error)
- func (r *Row) Err() error
- func (r *Row) MapScan(dest map[string]interface{}) error
- func (r *Row) Scan(dest ...interface{}) error
- func (r *Row) SliceScan() ([]interface{}, error)
- func (r *Row) StructScan(dest interface{}) error
- type Rows
- type Stmt
- func (s *Stmt) Get(dest interface{}, args ...interface{}) error
- func (s *Stmt) GetContext(ctx context.Context, dest interface{}, args ...interface{}) error
- func (s *Stmt) MustExec(args ...interface{}) sql.Result
- func (s *Stmt) MustExecContext(ctx context.Context, args ...interface{}) sql.Result
- func (s *Stmt) QueryRowX(args ...interface{}) *Row
- func (s *Stmt) QueryRowXContext(ctx context.Context, args ...interface{}) *Row
- func (s *Stmt) QueryX(args ...interface{}) (*Rows, error)
- func (s *Stmt) QueryXContext(ctx context.Context, args ...interface{}) (*Rows, error)
- func (s *Stmt) Select(dest interface{}, args ...interface{}) error
- func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error
- func (s *Stmt) Unsafe() *Stmt
- type Tx
- func (tx *Tx) BindNamed(query string, arg interface{}) (string, []interface{}, error)
- func (tx *Tx) DriverName() string
- func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (tx *Tx) MustExec(query string, args ...interface{}) sql.Result
- func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
- func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error)
- func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
- func (tx *Tx) NamedQuery(query string, arg interface{}) (*Rows, error)
- func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt
- func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt
- func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error)
- func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)
- func (tx *Tx) PrepareX(query string) (*Stmt, error)
- func (tx *Tx) PrepareXContext(ctx context.Context, query string) (*Stmt, error)
- func (tx *Tx) QueryRowX(query string, args ...interface{}) *Row
- func (tx *Tx) QueryRowXContext(ctx context.Context, query string, args ...interface{}) *Row
- func (tx *Tx) QueryX(query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) QueryXContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) Rebind(query string) string
- func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error
- func (tx *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (tx *Tx) StmtX(stmt interface{}) *Stmt
- func (tx *Tx) StmtXContext(ctx context.Context, stmt interface{}) *Stmt
- func (tx *Tx) Take(dest interface{}, query string, args ...interface{}) error
- func (tx *Tx) Unsafe() *Tx
Constants ¶
const ( Unknown = iota Question Dollar NAMED AT )
Rebind,BindMap 和 BindStruct 支持的BindVar类型。
Variables ¶
var (
NameMapper = strings.ToLower
)
NameMapper 用于将列名称映射到结构字段名称。默认情况下,它使用strings.ToLower来小写结构字段名称。
可以将其设置为所需的任何值,但建议在设置sqlx之前进行设置,因为在首次使用类型后会缓存名称到字段的映射。
1、尽管NameMapper很方便,但实际上除应用程序代码外不应依赖它。 2、如果要编写使用sqlx的库,则应注意,用户的应用程序可能会覆盖您期望的名称映射。
Functions ¶
func BindDriver ¶
BindDriver sets the BindType for driverName to bindType.
func BindNamed ¶
BindNamed binds a struct or a map to a query with named parameters. DEPRECATED: use sqlx.Named` instead of this, it may be removed in future.
func Get ¶
Get does a QueryRow using the provided Queryer, and scans the resulting row to dest. If dest is scannable, the result must only have one column. Otherwise, StructScan is used. Get will return sql.ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func GetContext ¶
func GetContext(ctx context.Context, q IQueryContext, dest interface{}, query string, args ...interface{}) error
GetContext does a QueryRow using the provided Queryer, and scans the resulting row to dest. If dest is scannable, the result must only have one column. Otherwise, StructScan is used. Get will return sql.ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func In ¶
In expands slice values in args, returning the modified query string and a new arg list that can be executed by a database. The `query` should use the `?` bindVar. The return value uses the `?` bindVar.
func LoadFile ¶
LoadFile exec's every statement in a file (as a single call to Exec). LoadFile may return a nil *sql.Result if errors are encountered locating or reading the file at path. LoadFile reads the entire file into memory, so it is not suitable for loading large data dumps, but can be useful for initializing schemas or loading indexes.
FIXME: this does not really work with multi-statement files for mattn/go-sqlite3 or the go-mysql-driver/mysql drivers; pq seems to be an exception here. Detecting this by requiring something with DriverName() and then attempting to split the queries will be difficult to get right, and its current driver-specific behavior is deemed at least not complex in its incorrectness.
func LoadFileContext ¶
LoadFileContext exec's every statement in a file (as a single call to Exec). LoadFileContext may return a nil *sql.Result if errors are encountered locating or reading the file at path. LoadFile reads the entire file into memory, so it is not suitable for loading large data dumps, but can be useful for initializing schemas or loading indexes.
FIXME: this does not really work with multi-statement files for mattn/go-sqlite3 or the go-mysql-driver/mysql drivers; pq seems to be an exception here. Detecting this by requiring something with DriverName() and then attempting to split the queries will be difficult to get right, and its current driver-specific behavior is deemed at least not complex in its incorrectness.
func MapScan ¶
func MapScan(r ColScanner, dest map[string]interface{}) error
MapScan scans a single Row into the dest map[string]interface{}. Use this to get results for SQL that might not be under your control (for instance, if you're building an interface for an SQL server that executes SQL from input). Please do not use this as a primary interface! This will modify the map sent to it in place, so reuse the same map with care. Columns which occur more than once in the result will overwrite each other!
func MustExec ¶
MustExec execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func MustExecContext ¶
func MustExecContext(ctx context.Context, e IExecuteContext, query string, args ...interface{}) sql.Result
MustExecContext execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func Named ¶
Named takes a query using named parameters and an argument and returns a new query with a list of args that can be executed by a database. The return value uses the `?` bindvar.
func NamedExec ¶
NamedExec uses BindStruct to get a query executable by the driver and then runs Exec on the result. Returns an error from the binding or the query execution itself.
func NamedExecContext ¶
func NamedExecContext(ctx context.Context, e ExtContext, query string, arg interface{}) (sql.Result, error)
NamedExecContext uses BindStruct to get a query executable by the driver and then runs Exec on the result. Returns an error from the binding or the query execution itself.
func Select ¶
Select executes a query using the provided Queryer, and StructScans each row into dest, which must be a slice. If the slice elements are scannable, then the result set must have only one column. Otherwise, StructScan is used. The *sql.Rows are closed automatically. Any placeholder parameters are replaced with supplied args.
func SelectContext ¶
func SelectContext(ctx context.Context, q IQueryContext, dest interface{}, query string, args ...interface{}) error
SelectContext executes a query using the provided Queryer, and StructScans each row into dest, which must be a slice. If the slice elements are scannable, then the result set must have only one column. Otherwise, StructScan is used. The *sql.Rows are closed automatically. Any placeholder parameters are replaced with supplied args.
func SliceScan ¶
func SliceScan(r ColScanner) ([]interface{}, error)
SliceScan a row, returning a []interface{} with values similar to MapScan. This function is primarily intended for use where the number of columns is not known. Because you can pass an []interface{} directly to Scan, it's recommended that you do that as it will not have to allocate new slices per row.
func StructScan ¶
StructScan all rows from an sql.Rows or an sqlx.Rows into the dest slice. StructScan will scan in the entire rows result, so if you do not want to allocate structs for the entire result, use Queryx and see sqlx.Rows.StructScan. If rows is sqlx.Rows, it will use its mapper, otherwise it will use the default.
Types ¶
type ColScanner ¶
type ColScanner interface { Columns() ([]string, error) Scan(dest ...interface{}) error Err() error }
ColScanner 是MapScan和SliceScan使用的接口。
type Conn ¶
Conn 是对 sql.Conn 的扩展。
func (*Conn) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginxContext is canceled.
func (*Conn) GetContext ¶
func (c *Conn) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
GetContext using this Conn. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Conn) PrepareXContext ¶
PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Conn) QueryRowXContext ¶
QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryXContext ¶
QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
type DB ¶
DB 是 sql.DB 的包装,在打开时跟踪driverName,通常用于使用正确的 bindVars 自动绑定命名查询。
func ConnectContext ¶
ConnectContext to a database and verify with a ping.
func MustConnect ¶
MustConnect 连接到数据库,并在出现错误时惊慌失措。
func NewDb ¶
NewDb returns a new sqlx DB wrapper for a pre-existing *sql.DB. The driverName of the original database is required for named query support.
func (*DB) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginxContext is canceled.
func (*DB) DriverName ¶
DriverName returns the driverName passed to the Open function for this DB.
func (*DB) GetContext ¶
func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
GetContext using this DB. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DB) MapperFunc ¶
MapperFunc 使用默认的 sqlx.struct 标记和提供的 mapper 函数为此数据库设置一个新的 mapper。
func (*DB) MustBeginTx ¶
MustBeginTx starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to MustBeginContext is canceled.
func (*DB) MustExecContext ¶
MustExecContext (panic) runs MustExec using this database. Any placeholder parameters are replaced with supplied args.
func (*DB) NamedExec ¶
NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedExecContext ¶
func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
NamedExecContext using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQuery ¶
NamedQuery using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQueryContext ¶
NamedQueryContext using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) PrepareNamed ¶
PrepareNamed 返回一个 *sqlx.NamedStmt
func (*DB) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*DB) PrepareXContext ¶
PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*DB) QueryRowXContext ¶
QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryXContext ¶
QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) SelectContext ¶
func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectContext using this DB. Any placeholder parameters are replaced with supplied args.
type ExtContext ¶
type ExtContext interface { IBind IQueryContext IExecuteContext }
ExtContext 是一个联合接口,可以与NamedQueryContext和NamedExecContext使用的Context绑定,查询和执行。
type IBind ¶
type IBind interface { DriverName() string Rebind(string) string BindNamed(string, interface{}) (string, []interface{}, error) }
IBind 是可以绑定查询(Tx,DB)的接口。
type IExecuteContext ¶
type IExecuteContext interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
IExecuteContext 是 MustExecContext 和 LoadFileContext 使用的接口
type IPrepareContext ¶
type IPrepareContext interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}
IPrepareContext 是 PreparexContext 使用的接口。
type IQuery ¶
type IQuery interface { Query(query string, args ...interface{}) (*sql.Rows, error) QueryX(query string, args ...interface{}) (*Rows, error) QueryRowX(query string, args ...interface{}) *Row }
IQuery 查询操作的接口。
type IQueryContext ¶
type IQueryContext interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryXContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) QueryRowXContext(ctx context.Context, query string, args ...interface{}) *Row }
IQueryContext 是 GetContext 和 SelectContext 使用的接口
type IRow ¶
type IRow interface { Columns() ([]string, error) Scan(...interface{}) error Err() error Next() bool Close() error }
IRow 是 ColScanner 和 io.Closer 的联合接口。
type NamedStmt ¶
NamedStmt is a prepared statement that executes named queries. Prepare it how you would execute a NamedQuery, but pass in a struct or map when executing.
func (*NamedStmt) Exec ¶
Exec executes a named statement using the struct passed. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) ExecContext ¶
ExecContext executes a named statement using the struct passed. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Get ¶
Get using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) GetContext ¶
GetContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) MustExec ¶
MustExec execs a NamedStmt, panicing on error Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) MustExecContext ¶
MustExecContext execs a NamedStmt, panicing on error Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Query ¶
Query executes a named statement using the struct argument, returning rows. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryContext ¶
QueryContext executes a named statement using the struct argument, returning rows. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRow ¶
QueryRow executes a named statement against the database. Because sqlx cannot create a *sql.Row with an error condition pre-set for binding errors, sqlx returns a *sqlx.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowContext ¶
QueryRowContext executes a named statement against the database. Because sqlx cannot create a *sql.Row with an error condition pre-set for binding errors, sqlx returns a *sqlx.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowX ¶
QueryRowX this NamedStmt. Because of limitations with QueryRow, this is an alias for QueryRow. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowxContext ¶
QueryRowxContext this NamedStmt. Because of limitations with QueryRow, this is an alias for QueryRow. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryX ¶
QueryX using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryxContext ¶
QueryxContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Select ¶
Select using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) SelectContext ¶
SelectContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
type Row ¶
Row 是对 sql.Row 的重新实现,以便获得对 StructScan 必需的基础 sql.Rows.Columns() 数据的访问。
func (*Row) ColumnTypes ¶
func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error
func (*Row) StructScan ¶
StructScan a single Row into dest.
type Rows ¶
Rows 是对 sql.Rows 的扩展
func NamedQuery ¶
NamedQuery binds a named query and then runs Query on the result using the provided Ext (sqlx.Tx, sqlx.Db). It works with both structs and with map[string]interface{} types.
func NamedQueryContext ¶
func NamedQueryContext(ctx context.Context, e ExtContext, query string, arg interface{}) (*Rows, error)
NamedQueryContext binds a named query and then runs Query on the result using the provided Ext (sqlx.Tx, sqlx.Db). It works with both structs and with map[string]interface{} types.
func (*Rows) StructScan ¶
StructScan is like sql.Rows.Scan, but scans a single Row into a single Struct. Use this and iterate over Rows manually when the memory load of Select() might be prohibitive. *Rows.StructScan caches the reflect work of matching up column positions to fields to avoid that overhead per scan, which means it is not safe to run StructScan on the same Rows instance with different struct types.
type Stmt ¶
Stmt 是 sql.Stmt 的扩展。
func PreparexContext ¶
PreparexContext prepares a statement.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Stmt) Get ¶
Get using the prepared statement. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Stmt) GetContext ¶
GetContext using the prepared statement. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Stmt) MustExec ¶
MustExec (panic) using this statement. Note that the query portion of the error output will be blank, as Stmt does not expose its query. Any placeholder parameters are replaced with supplied args.
func (*Stmt) MustExecContext ¶
MustExecContext (panic) using this statement. Note that the query portion of the error output will be blank, as Stmt does not expose its query. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryRowX ¶
QueryRowX using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryRowXContext ¶
QueryRowxContext using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryX ¶
QueryX using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryXContext ¶
QueryxContext using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) Select ¶
Select using the prepared statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) SelectContext ¶
SelectContext using the prepared statement. Any placeholder parameters are replaced with supplied args.
type Tx ¶
Tx 是对 sql.Tx 的扩展。
func (*Tx) GetContext ¶
func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
GetContext within a transaction and context. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Tx) MustExecContext ¶
MustExecContext runs MustExecContext within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) NamedExecContext ¶
func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
NamedExecContext using this Tx. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedStmtContext ¶
NamedStmtContext returns a version of the prepared statement which runs within a transaction.
func (*Tx) PrepareNamed ¶
PrepareNamed 返回一个 *sqlx.NamedStmt
func (*Tx) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*Tx) PrepareXContext ¶
PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Tx) QueryRowXContext ¶
QueryRowxContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryXContext ¶
QueryxContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) SelectContext ¶
func (tx *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) StmtXContext ¶
StmtxContext returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt.