Documentation ¶
Overview ¶
Package sqlite3 provides SQLite helpers for golembic.
Index ¶
- Constants
- Variables
- type Config
- type Option
- type SQLProvider
- func (*SQLProvider) NewCreateTableParameters() golembic.CreateTableParameters
- func (sp *SQLProvider) Open() (*sql.DB, error)
- func (*SQLProvider) QueryParameter(index int) string
- func (sp *SQLProvider) QuoteIdentifier(name string) string
- func (sp *SQLProvider) QuoteLiteral(literal string) string
- func (sp *SQLProvider) TableExistsSQL() string
- func (*SQLProvider) TimestampColumn() golembic.TimestampColumn
- type TimeFromInteger
Constants ¶
const ( // DefaultDataSourceName is the DSN / connection string for completely // in-memory values. Richer support for SQLite connection strings can be // added if desired; for reference: https://www.sqlite.org/uri.html DefaultDataSourceName = "file::memory:?cache=shared" // DefaultDriverName is the default SQL driver to be used when creating // a new database connection pool via `sql.Open()`. This default driver // is expected to be registered by importing one of // - github.com/gwenn/gosqlite // - github.com/mattn/go-sqlite3 // - github.com/mxk/go-sqlite // - github.com/rsc/sqlite // - modernc.org/sqlite DefaultDriverName = "sqlite3" )
Variables ¶
var ( // ErrTimestampNotInteger is the error returned when a TimeFromInteger column // is expected but the value in the database is not an integer. ErrTimestampNotInteger = errors.New("Timestamp was not stored as an integer") // ErrTimestampRounding is the error returned when a TimeFromInteger column // can't be converted an integer (e.g. microseconds since the epoch) without // rounding. ErrTimestampRounding = errors.New("Timestamp cannot be converted to integer without rounding") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // DataSourceName is the DSN or connection string for a SQLite connection. DataSourceName string // DriverName specifies the name of SQL driver to be used when creating // a new database connection pool via `sql.Open()`. The default driver // is expected to be registered by importing `github.com/mattn/go-sqlite3`, // though `https://github.com/golang/go/wiki/SQLDrivers` lists (as of // January 9, 2021) four other implementations that all register the // same driver name // - github.com/gwenn/gosqlite // - github.com/mxk/go-sqlite // - github.com/rsc/sqlite // - modernc.org/sqlite DriverName string }
Config is a set of connection config options.
type Option ¶
Option describes options used to create a new config for a SQL provider.
func OptDataSourceName ¶
OptDataSourceName sets the `DataSourceName` on a `Config`.
func OptDriverName ¶
OptDriverName sets the `DriverName` on a `Config`.
type SQLProvider ¶
type SQLProvider struct {
Config *Config
}
SQLProvider is a SQLite-specific database engine provider.
func New ¶
func New(opts ...Option) (*SQLProvider, error)
New creates a SQLite-specific database engine provider from some options.
func (*SQLProvider) NewCreateTableParameters ¶
func (*SQLProvider) NewCreateTableParameters() golembic.CreateTableParameters
NewCreateTableParameters produces the SQL expressions used in the the `CREATE TABLE` statement used to create the migrations table.
func (*SQLProvider) Open ¶
func (sp *SQLProvider) Open() (*sql.DB, error)
Open creates a database connection pool to a SQLite instance.
func (*SQLProvider) QueryParameter ¶
func (*SQLProvider) QueryParameter(index int) string
QueryParameter produces the placeholder `?NNN` for a numbered parameter in a SQLite query.
func (*SQLProvider) QuoteIdentifier ¶
func (sp *SQLProvider) QuoteIdentifier(name string) string
QuoteIdentifier quotes an identifier, such as a table name, for usage in a query. See: https://www.sqlite.org/lang_keywords.html
func (*SQLProvider) QuoteLiteral ¶
func (sp *SQLProvider) QuoteLiteral(literal string) string
QuoteLiteral quotes a literal, such as `2023-01-05 15:00:00Z`, for usage in a query. See: https://www.sqlite.org/lang_keywords.html
func (*SQLProvider) TableExistsSQL ¶
func (sp *SQLProvider) TableExistsSQL() string
TableExistsSQL returns a SQL query that can be used to determine if a table exists.
See: https://www.sqlite.org/fileformat2.html#storage_of_the_sql_database_schema
func (*SQLProvider) TimestampColumn ¶
func (*SQLProvider) TimestampColumn() golembic.TimestampColumn
TimestampColumn produces a value that can be used for reading / writing an `INTEGER` column to a `time.Time` in SQLite.
type TimeFromInteger ¶
TimeFromInteger represents a `time.Time` stored in a database as an `INTEGER` number of microseconds (in UTC) since the epoch.
This is **necessary** because SQLite doesn't have rich support for timestamps and the drivers can't paper over this issue, e.g. https://github.com/mattn/go-sqlite3/issues/142
func (*TimeFromInteger) Pointer ¶
func (tfi *TimeFromInteger) Pointer() interface{}
Pointer returns the current pointer receiver.
func (*TimeFromInteger) Scan ¶
func (tfi *TimeFromInteger) Scan(src interface{}) error
Scan implements the Scanner interface.
func (TimeFromInteger) Timestamp ¶
func (tfi TimeFromInteger) Timestamp() time.Time
Timestamp returns the stored timestamp value.