Documentation ¶
Index ¶
- func ExecContext(db Execer, ctx context.Context, query string, data any, cfg *Config) (sql.Result, error)
- func OptBindvar(p bindvar.Parser) func(c *Config)
- func OptDriver(s string) func(c *Config)
- func OptQuiet() func(c *Config)
- func OptTemplate(e template.Executer) func(c *Config)
- type Config
- type DB
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Exec(query string, data interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, data interface{}) (sql.Result, error)
- func (db *DB) Query(query string, data interface{}) (*Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, data interface{}) (*Rows, error)
- func (db *DB) QueryRow(query string, data interface{}) *Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, data interface{}) *Row
- type Execer
- type ExecerQueryer
- type Queryer
- type Row
- type Rows
- type Tx
- func (tx *Tx) Exec(query string, data interface{}) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, query string, data interface{}) (sql.Result, error)
- func (tx *Tx) Query(ctx context.Context, query string, data interface{}) (*Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, data interface{}) (*Rows, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecContext ¶
func ExecContext( db Execer, ctx context.Context, query string, data any, cfg *Config, ) (sql.Result, error)
ExecContext executes a query without returning any rows, e.g. an INSERT. The data object is a map/struct for any placeholder parameters in the query.
func OptBindvar ¶ added in v0.2.0
OptBindvar sets the bindvar parser.
func OptTemplate ¶ added in v0.2.0
OptTemplate sets the template executer.
Types ¶
type Config ¶ added in v0.2.0
type Config struct {
// contains filtered or unexported fields
}
Config stores runtime config for yesql.
type DB ¶
func MustOpen ¶
MustOpen opens a database specified by its database driver name and a driver-specific data source name, and panics on any errors.
func Open ¶
Open opens a database specified by its database driver name and a driver-specific data source name, usually consisting of at least a database name and connection information.
Most users will open a database via a driver-specific connection helper function that returns a *DB. No database drivers are included in the Go standard library. See https://golang.org/s/sqldrivers for a list of third-party drivers.
Open may just validate its arguments without creating a connection to the database. To verify that the data source name is valid, call Ping.
The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.
func (*DB) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginTx ¶
BeginTx starts a 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 the context provided to BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*DB) Exec ¶
Exec executes a query without returning any rows, e.g. an INSERT. The data object is a map/struct for any placeholder parameters in the query.
func (*DB) ExecContext ¶
ExecContext executes a query without returning any rows, e.g. an INSERT. The data object is a map/struct for any placeholder parameters in the query.
func (*DB) Query ¶
Query executes a query that returns rows, typically a SELECT. The data object is a map/struct for any placeholder parameters in the query.
func (*DB) QueryContext ¶
QueryContext executes a query that returns rows, typically a SELECT. The data object is a map/struct for any placeholder parameters in the query.
func (*DB) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
QueryRow uses context.Background internally; to specify the context, use QueryRowContext.
func (*DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
type ExecerQueryer ¶
ExecerQueryer is a union interface comprising Execer and Queryer.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row is the result of calling QueryRow to select a single row. It's a re-implementation of *sql.Row because the standard type is inaccessible.
func QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Row) Err ¶
Err provides a way for wrapping packages to check for query errors without calling Scan. Err returns the error, if any, that was encountered while running the query. If this error is not nil, this error will also be returned from Scan.
func (*Row) Scan ¶
Scan copies the columns from the matched row into the values pointed at by dest. See the documentation on Rows.Scan for details. If more than one row matches the query, Scan uses the first row and discards the rest. If no row matches the query, Scan returns ErrNoRows.
func (*Row) ScanStruct ¶
ScanStruct copies the columns in the current row into the values pointed at by the dest struct.
ScanStruct is like Rows.Scan, but doesn't rely on positional scanning, and instead scans into a struct based on the column names and the db struct tags, e.g. Foo string `db:"foo"`.
type Rows ¶
Rows is the result of a query. Its cursor starts before the first row of the result set. Use Next to advance from row to row.
func QueryContext ¶
func QueryContext( db Queryer, ctx context.Context, query string, data any, cfg *Config, ) (*Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The data object is a map/struct for any placeholder parameters in the query.
func (*Rows) ScanStruct ¶
ScanStruct copies the columns in the current row into the values pointed at by the dest struct.
ScanStruct is like Rows.Scan, but doesn't rely on positional scanning, and instead scans into a struct based on the column names and the db struct tags, e.g. Foo string `db:"foo"`.
type Tx ¶
Tx is an in-progress database transaction.
A transaction must end with a call to Commit or Rollback.
After a call to Commit or Rollback, all operations on the transaction fail with ErrTxDone.
The statements prepared for a transaction by calling the transaction's Prepare or Stmt methods are closed by the call to Commit or Rollback.
func (*Tx) Exec ¶
Exec executes a query without returning any rows. The data object is a map/struct for any placeholder parameters in the query.
func (*Tx) ExecContext ¶
ExecContext executes a query that doesn't return rows. The data object is a map/struct for any placeholder parameters in the query.