Documentation
¶
Overview ¶
Package database defines a generic Store interface for interacting with the database.
Use the NewStore function to create a Store for one of the supported dialects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DBTxConn ¶
type DBTxConn interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
DBTxConn is a thin interface for common methods that is satisfied by *sql.DB, *sql.Tx and *sql.Conn.
There is a long outstanding issue to formalize a std lib interface, but alas. See: https://github.com/golang/go/issues/14468
type Store ¶
type Store interface {
// Tablename is the name of the table where the version is tracked.
Tablename() string
// CreateVersionTable creates the version table.
CreateVersionTable(ctx context.Context, db DBTxConn) error
// UpdateVersion updates the version in the database.
UpdateVersion(ctx context.Context, db DBTxConn, version int64) error
// InsertVersion inserts a version into the version table. Only used to initialize the version table.
InsertVersion(ctx context.Context, db DBTxConn, version int64) error
// GetVersion retrieves the current version from the database.
GetVersion(ctx context.Context, db DBTxConn) (int64, error)
// VersionTableExists checks if the version table exists in the database.
VersionTableExists(ctx context.Context, db DBTxConn) (bool, error)
}
Store is an interface that defines methods for tracking and managing the database version. It is used by brant to interact with a database. The dialect package provides several dialects for which a Store interface can be created (see NewStore). To support a new database, implementing a new dialect.Dialect should usually be sufficient.