Documentation
¶
Overview ¶
Package liteflow encourages keeping SQL statements in separate files. Instead of passing SQL and arguments, you pass a statement name and arguments. To generate the named statements internally, pass an io/fs.FS (e.g.: embed.FS) which contains the SQL files.
This package can also handle database migrations for SQLite.
Index ¶
- Constants
- type DB
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Downgrade(vDownTo int) (int, error)
- func (db *DB) Exec(name string, args ...any) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, name string, args ...any) (sql.Result, error)
- func (db *DB) Query(name string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, name string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryRow(name string, args ...any) (*sql.Row, error)
- func (db *DB) QueryRowContext(ctx context.Context, name string, args ...any) (*sql.Row, error)
- func (db *DB) Upgrade(vUpTo int) (int, error)
- func (db *DB) Version() (int, error)
- type Options
- type Tx
- func (tx *Tx) Exec(name string, args ...any) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, name string, args ...any) (sql.Result, error)
- func (tx *Tx) Query(name string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, name string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryRow(name string, args ...any) (*sql.Row, error)
- func (tx *Tx) QueryRowContext(ctx context.Context, name string, args ...any) (*sql.Row, error)
Constants ¶
const UpgradeAll int = 0
UpgradeAll indicates to perform all database upgrades available.
const UpgradeNone int = -1
UpgradeNone indicates to skip upgrading and prepared statements.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is an enhanced SQLite *sql.DB with versioning and named statements.
func New ¶
New creates DB, which is an enhanced *sql.DB with version control and named prepared statements.
See Options documentation for the available configurations.
If the returned database is non-nil, it may still be usable even if there were errors.
func (*DB) Begin ¶
Begin is like sql.DB.Begin, but returns a *liteflow.Tx for named queries.
func (*DB) BeginTx ¶
BeginTx is like sql.DB.BeginTx, but returns a *liteflow.Tx for named queries.
func (*DB) Downgrade ¶
Downgrade decrements the database to the given version. The actual version and any error are returned.
func (*DB) Exec ¶
Exec is sql.DB.Exec but with a query name.
func (*DB) ExecContext ¶
ExecContext is sql.DB.ExecContext but with a query name.
func (*DB) Query ¶
Query is sql.DB.Query but with a query name.
func (*DB) QueryContext ¶
QueryContext is sql.DB.QueryContext but with a query name.
func (*DB) QueryRow ¶
QueryRow is sql.DB.QueryRow but with a query name.
func (*DB) QueryRowContext ¶
QueryRowContext is sql.DB.QueryRowContext but with a query name.
func (*DB) Upgrade ¶
Upgrade increments the database to at _most_ the given version. The actual version and any error are returned. Passing a version of zero will upgrade as far as possible.
type Options ¶
type Options struct {
// MaxVersion is the maximum database upgrade to run. The default zero value
// indicates to run all available upgrades.
MaxVersion int
// NoPreload indicates to skip the normal preloading of all SQL queries into
// sql.Stmt objects for later use. Setting this to true will not catch
// errors in SQL statements until they are actually used.
NoPreload bool
// VersionFS is the sub-directory in the fs.FS which holds the numbered
// database migration files.
VersionFS fs.FS
// InitFS is the filesystem holding initialization scripts, run in file
// lexical sort order.
InitFS fs.FS
// QueryFS is the sub-directory in the fs.FS which holds all prepared
// statements.
QueryFS fs.FS
}
Options are additional options for database upgrade.
type Tx ¶
Tx is like sql.Tx but uses named parameters.
func (*Tx) Exec ¶
Exec is like sql.Tx.Exec but with a query name.
func (*Tx) ExecContext ¶
ExecContext is like sql.Tx.ExecContext but with a query name.
func (*Tx) Query ¶
Query is like sql.Tx.Query but with a query name.
func (*Tx) QueryContext ¶
QueryContext is like sql.Tx.QueryContext but with a query name.
func (*Tx) QueryRow ¶
QueryRow is like sql.Tx.QueryRow but with a query name.
Source Files
¶
- liteflow.go