Documentation
¶
Index ¶
- func RunInTransaction(ctx context.Context, db DB, fn func(tx *Tx) error) (err error)
- type Conn
- func (c *Conn) As(in interface{}) error
- func (c *Conn) Begin() (*Tx, error)
- func (c *Conn) BeginTx(ctx context.Context, options *sql.TxOptions) (*Tx, error)
- func (c *Conn) BindNamed(q string, arg interface{}) (query string, args []interface{}, err error)
- func (c *Conn) DriverName() string
- func (c *Conn) Exec(query string, args ...interface{}) (sql.Result, error)
- func (c *Conn) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (c *Conn) Ping() error
- func (c *Conn) PingContext(ctx context.Context) error
- func (c *Conn) Prepare(query string) (*Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (c *Conn) Query(query string, args ...interface{}) (*Rows, error)
- func (c *Conn) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (c *Conn) QueryRow(query string, args ...interface{}) *Row
- func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (c *Conn) Rebind(query string) string
- func (c *Conn) RunInTransaction(ctx context.Context, fn func(tx *Tx) error) error
- type DB
- type Row
- func (r *Row) As(in interface{}) error
- 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
- func (r *Rows) As(in interface{}) error
- func (r *Rows) Close() error
- func (r *Rows) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Rows) Columns() ([]string, error)
- func (r *Rows) Err() error
- func (r *Rows) MapScan(dest map[string]interface{}) error
- func (r *Rows) Next() bool
- func (r *Rows) NextResultSet() bool
- func (r *Rows) Scan(dest ...interface{}) error
- func (r *Rows) SliceScan() ([]interface{}, error)
- func (r *Rows) StructScan(dest interface{}) error
- type Stmt
- func (s *Stmt) As(in interface{}) error
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args ...interface{}) (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)
- func (s *Stmt) Query(args ...interface{}) (*Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error)
- func (s *Stmt) QueryRow(args ...interface{}) *Row
- func (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row
- type Tx
- func (tx *Tx) As(in interface{}) error
- func (tx *Tx) BindNamed(s string, i interface{}) (string, []interface{}, error)
- func (tx *Tx) Commit() error
- func (tx *Tx) DriverName() string
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) Prepare(query string) (*Stmt, error)
- func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) QueryRow(query string, args ...interface{}) *Row
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (tx *Tx) Rebind(s string) string
- func (tx *Tx) Rollback() error
- func (tx *Tx) RunInTransaction(fn func(tx *Tx) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
Conn is the database connection.
func Connect ¶
Connect establish a new database connection using provided driverName and given dataSourceName (DSN).
func (*Conn) BeginTx ¶
BeginTx starts a new transaction. 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 this context is canceled.
func (*Conn) DriverName ¶
DriverName gets the name of the driver provided during establishing connection.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes provided query with the input arguments. The connection is aware of given context.
func (*Conn) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*Conn) PingContext ¶
PingContext verifies a connection to the database is still alive, establishing a connection if necessary.
func (*Conn) PrepareContext ¶
PrepareContext creates a prepared statement. Provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Conn) Query ¶
Query queries the database and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryContext ¶
QueryContext queries the database and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryRow ¶
QueryRow queries the database and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryRowContext ¶
QueryRowContext queries the database and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.
type DB ¶
type DB interface {
// QueryContext queries the database and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
// QueryRowContext queries the database and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.
QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
// Query queries the database and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
Query(query string, args ...interface{}) (*Rows, error)
// QueryRow queries the database and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.
QueryRow(query string, args ...interface{}) *Row
// ExecContext executes provided query with the input arguments.
// The connection is aware of given context.
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// Exec execute provided query with the input arguments.
Exec(query string, args ...interface{}) (sql.Result, error)
// PrepareContext creates a prepared statement.
// Provided context is used for the preparation of the statement, not for the execution of the statement.
PrepareContext(ctx context.Context, query string) (*Stmt, error)
// Prepare creates a prepared statement.
Prepare(query string) (*Stmt, error)
// As extracts the types on which given implementation is based on.
// I.e: Tx accepts: **sqlx.Tx or **sql.Tx.
As(in interface{}) error
// Rebind changes argument format in provided query.
Rebind(query string) string
}
DB is the common interface for both the Conn and Tx.
type Row ¶
Row is the row type wrapper of the sqlx.Row.
func (*Row) ColumnTypes ¶
func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error.
func (*Row) Columns ¶
Columns returns the underlying sql.Rows.Columns(), or the deferred error usually returned by Row.Scan()
func (*Row) Scan ¶
Scan is a fixed implementation of sql.Row.Scan, which does not discard the underlying error from the internal rows object if it exists.
func (*Row) StructScan ¶
StructScan scans the row as a structure provided as argument.
type Rows ¶
Rows is the simple type wrapper for the sqlx.Rows that provides minor enhancement.
func (*Rows) As ¶
As extracts the *sqlx.Rows or *sql.Rows implementation by providing a pointer to it.
func (*Rows) Close ¶
Close closes the Rows, preventing further enumeration. If Next is called and returns false and there are no further result sets, the Rows are closed automatically, and it will suffice to check the result of Err. Close is idempotent and does not affect the result of Err.
func (*Rows) ColumnTypes ¶
func (r *Rows) ColumnTypes() ([]*sql.ColumnType, error)
ColumnTypes returns column information such as column type, length, and nullable. Some information may not be available from some drivers.
func (*Rows) Err ¶
Err returns the error, if any, that was encountered during iteration. It may be called after an explicit or implicit Close.
func (*Rows) Next ¶
Next prepares the next result row for reading with the Scan method. It returns true on success, or false if there is no next result row, or an error happened while preparing it. Err should be consulted to distinguish between the two cases. Every call to Scan, even the first one, must be preceded by a call to Next.
func (*Rows) NextResultSet ¶
NextResultSet prepares the next result set for reading. It reports whether there is further result sets, or false if there is no further result set or if there is an error advancing to it. The Err method should be consulted to distinguish between the two cases. After calling NextResultSet, the Next method should always be called before scanning. If there are further result sets they may not have rows in the result set.
func (*Rows) Scan ¶
Scan copies the columns in the current row into the values pointed at by dest. The number of values in dest must be the same as the number of columns in Rows. It converts columns read from the database into the following common Go types and special types provided by the sql package: - *string - *[]byte - *int, *int8, *int16, *int32, *int64 - *uint, *uint8, *uint16, *uint32, *uint64 - *bool - *float32, *float64 - *interface{} - *RawBytes - *Rows (cursor value) any type implementing Scanner (see Scanner docs) In the most simple case, if the type of the value from the source column is an integer, bool or string type T and dest is of type *T, Scan simply assigns the value through the pointer. Scan also converts between string and numeric types, as long as no information would be lost. While Scan stringifies all numbers scanned from numeric database columns into *string, scans into numeric types are checked for overflow. For example, a float64 with value 300, or a string with value "300" can scan into a uint16, but not into a uint8, though float64(255) or "255" can scan into an uint8. One exception is that scans of some float64 numbers to strings may lose information when stringifying. In general, scan floating point columns into *float64. If a dest argument has type *[]byte, Scan saves in that argument a copy of the corresponding data. The copy is owned by the caller and can be modified and held indefinitely. The copy can be avoided by using an argument of type *RawBytes instead; see the documentation for RawBytes for restrictions on its use. If an argument has type *interface{}, Scan copies the value provided by the underlying driver without conversion. When scanning from a source value of type []byte to *interface{}, a copy of the slice is made, and the caller owns the result. Source values of type time.Time may be scanned into values of type *time.Time, *interface{}, *string, or *[]byte. When converting to the latter two, time.RFC3339Nano is used. Source values of type bool may be scanned into types *bool, *interface{}, *string, *[]byte, or *RawBytes. For scanning into *bool, the source may be true, false, 1, 0, or string inputs parseable by strconv.ParseBool. Scan can also convert a cursor returned from a query, such as "select cursor(select * from my_table) from dual", into a *Rows value that can itself be scanned from. The parent select query will close any cursor *Rows if the parent *Rows is closed. If any of the first arguments implementing Scanner returns an error, that error will be wrapped in the returned error.
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 reflection 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 ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt is the xsql type wrapper for the sqlx.Stmt.
func (*Stmt) ExecContext ¶
ExecContext executes the statement with provided arguments.
func (*Stmt) QueryContext ¶
QueryContext executes statement query with provided arguments.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is the database connection.
func (*Tx) DriverName ¶
DriverName gets the name of the driver provided during establishing connection.
func (*Tx) ExecContext ¶
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext execute provided query with the input arguments.
func (*Tx) PrepareContext ¶
PrepareContext creates a prepared statement. Provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Tx) Query ¶
Query queries the database within given transaction and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryContext ¶
QueryContext queries the database within given transaction and returns an *xsql.Rows. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryRow ¶
QueryRow queries the database within given transaction and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryRowContext ¶
QueryRowContext queries the database within given transaction and returns an *xsql.Row. Any placeholder parameters are replaced with supplied args.