Documentation ¶
Overview ¶
Package sqldb provides Encore services direct access to their databases.
For the documentation on how to use databases within Encore see https://encore.dev/docs/develop/databases.
Index ¶
- Variables
- func Commit(tx *Tx) error
- func Rollback(tx *Tx) error
- type Database
- func (*Database) Begin(ctx context.Context) (*Tx, error)
- func (*Database) Exec(ctx context.Context, query string, args ...interface{}) (ExecResult, error)
- func (*Database) Query(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (*Database) QueryRow(ctx context.Context, query string, args ...interface{}) *Row
- func (*Database) Stdlib() *sql.DB
- type ExecResult
- type Row
- type Rows
- type Tx
- func (*Tx) Commit() error
- func (*Tx) Exec(ctx context.Context, query string, args ...interface{}) (ExecResult, error)
- func (*Tx) Query(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (*Tx) QueryRow(ctx context.Context, query string, args ...interface{}) *Row
- func (*Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
var ErrNoRows = sql.ErrNoRows
ErrNoRows is an error reported by Scan when QueryRow doesn't return a row. It must be tested against with errors.Is.
Functions ¶
Types ¶
type Database ¶ added in v0.17.0
type Database struct {
// contains filtered or unexported fields
}
func Named ¶ added in v0.17.0
func Named(name constStr) *Database
Named returns a database object connected to the database with the given name.
The name must be a string literal constant, to facilitate static analysis.
func (*Database) Begin ¶ added in v0.17.0
Begin opens a new database transaction.
See (*database/sql.DB).Begin() for additional documentation.
func (*Database) Exec ¶ added in v0.17.0
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
See (*database/sql.DB).ExecContext() for additional documentation.
func (*Database) Query ¶ added in v0.17.0
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
See (*database/sql.DB).QueryContext() for additional documentation.
type ExecResult ¶ added in v0.17.0
type ExecResult interface { // RowsAffected returns the number of rows affected. If the result was not // for a row affecting command (e.g. "CREATE TABLE") then it returns 0. RowsAffected() int64 }
ExecResult is the result of an Exec query.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row is the result of calling QueryRow to select a single row.
See *database/sql.Row for additional documentation.
func QueryRow ¶
QueryRow executes a query that is expected to return at most one row.
See (*database/sql.DB).QueryRowContext() for additional documentation.
func QueryRowTx ¶
QueryRowTx is like QueryRow but executes the query in the given transaction.
See (*database/sql.Tx).QueryRowContext() for additional documentation. Deprecated: use tx.QueryRow() instead.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
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.
See *database/sql.Rows for additional documentation.
func Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
See (*database/sql.DB).QueryContext() for additional documentation.
func QueryTx ¶
QueryTx is like Query but executes the query in the given transaction.
See (*database/sql.Tx).QueryContext() for additional documentation. Deprecated: use tx.Query() instead.
func (*Rows) Close ¶
func (*Rows) Close()
Close closes the Rows, preventing further enumeration.
See (*database/sql.Rows).Close() for additional documentation.
func (*Rows) Err ¶
Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.
See (*database/sql.Rows).Err() for additional documentation.
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.
See (*database/sql.Rows).Next() for additional documentation.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a handle to a database transaction.
See *database/sql.Tx for additional documentation.
func Begin ¶
Begin opens a new database transaction.
See (*database/sql.DB).Begin() for additional documentation.
func (*Tx) Commit ¶ added in v0.17.0
Commit commits the given transaction.
See (*database/sql.Tx).Commit() for additional documentation.