Documentation ¶
Index ¶
- func Exec(ctx context.Context, db Queryer, query string, args ...any) (sql.Result, error)
- func Get[T any](ctx context.Context, db Queryer, query string, args ...any) (result T, err error)
- func Query(ctx context.Context, db Queryer, query string, args ...any) (*sql.Rows, error)
- func Select[T any](ctx context.Context, db Queryer, query string, args ...any) (results []T, err error)
- type Database
- func (db *Database) Begin(ctx context.Context) (*Tx, error)
- func (db *Database) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *Database) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (db *Database) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (db *Database) Ping(ctx context.Context) error
- func (db *Database) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (db *Database) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
- func (db *Database) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
- func (db *Database) Select(ctx context.Context, dest any, query string, args ...any) error
- func (db *Database) SetConnMaxLifetime(d time.Duration)
- func (db *Database) SetMaxIdleConns(n int)
- func (db *Database) SetMaxOpenConns(n int)
- func (db *Database) Stats() sql.DBStats
- type Queryer
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (tx *Tx) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
- func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) Select(ctx context.Context, dest any, query string, args ...any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is wrapper of `sqlx.DB` which implements `DB`
func Connect ¶
Connect to a database and verify the connections with a ping. See https://www.alexedwards.net/blog/configuring-sqldb and https://making.pusher.com/production-ready-connection-pooling-in-go https://brandur.org/fragments/postgres-parameters for the details
func (*Database) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver. 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.
func (*Database) 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 (*Database) ExecContext ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Database) GetContext ¶
Get a single record. Any placeholder parameters are replaced with supplied args. An `ErrNoRows` error is returned if the result set is empty.
func (*Database) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*Database) QueryContext ¶
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Database) QueryRowxContext ¶
func (*Database) QueryxContext ¶
func (*Database) Select ¶
Select an array of records. Any placeholder parameters are replaced with supplied args.
func (*Database) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
func (*Database) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*Database) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to the database.
type Queryer ¶
type Queryer interface { sqlx.QueryerContext sqlx.ExecerContext }
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Transaction is wrapper of `sqlx.Tx` which implements `Tx`
func (*Tx) ExecContext ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Tx) GetContext ¶
Get a single record. Any placeholder parameters are replaced with supplied args. An `ErrNoRows` error is returned if the result set is empty.
func (*Tx) QueryContext ¶
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.