Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyMigrations(db *sql.DB, migrations *ConfigMigrations, max int) (int, error)
- func GetDB(ctx context.Context) *sql.DB
- func Initializer(ctx context.Context) (injectz.Injector, injectz.Releaser)
- func NewConfigSingletonInjector(cfg *Config) injectz.Injector
- func RevertMigrations(db *sql.DB, migrations *ConfigMigrations, max int) (int, error)
- type Config
- type ConfigDBSpec
- type ConfigMigrations
- type ContextSQLite
- type SQLite
Constants ¶
const (
// AllMigrations means apply/revert all migrations.
AllMigrations = -1
)
Variables ¶
var ( // DefaultPragmas provides a default, sane set of PRAGMAs for opening SQLite databases. DefaultPragmas = map[string]interface{}{ "auto_vacuum": 2, "cache_size": -2000, "foreign_keys": 1, "ignore_check_constraints": 0, "locking_mode": "normal", "synchronous": 2, "writable_schema": 0, } )
Functions ¶
func ApplyMigrations ¶
ApplyMigrations applies the given migrations.
func Initializer ¶
Initializer is a SQLite initializer.
func NewConfigSingletonInjector ¶
NewConfigSingletonInjector always inject the given *Config.
func RevertMigrations ¶
RevertMigrations reverts the given migrations.
Types ¶
type Config ¶
type Config struct { DBSpec *ConfigDBSpec `json:"dbSpec" validate:"required"` ApplyMigrations *ConfigMigrations `json:"-"` }
Config describes the configuration for SQLite.
type ConfigDBSpec ¶
type ConfigDBSpec struct { FilePath string `json:"filePath" validate:"required"` Pragmas map[string]interface{} `json:"pragmas" validate:"required"` }
ConfigDBSpec describes part of the configuration for SQLite.
func NewConfigDBSpec ¶
func NewConfigDBSpec(filePath string, pragmas map[string]interface{}) *ConfigDBSpec
NewConfigDBSpec initializes a new *ConfigDBSpec.
func NewDefaultConfigDBSpec ¶
func NewDefaultConfigDBSpec(filePath string) *ConfigDBSpec
NewDefaultConfigDBSpec initializes a new *ConfigDBSpec with the default PRAGMAs.
func (*ConfigDBSpec) ToOpen ¶
func (c *ConfigDBSpec) ToOpen() string
ToOpen converts the *ConfigDBSpec to a string that can be passed to sql.Open().
type ConfigMigrations ¶
type ConfigMigrations struct { EmbedFS embed.FS `json:"-" validate:"required"` EmbedMigrationsDirPath string `json:"embedMigrationsDirPath" validate:"required"` }
ConfigMigrations describes part of the configuration for SQLite.
func NewConfigMigrations ¶
func NewConfigMigrations(embedFS embed.FS, embedMigrationsDirPath string) *ConfigMigrations
NewConfigMigrations initializes a new *ConfigMigrations.
type ContextSQLite ¶
type ContextSQLite interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
ContextSQLite describes a SQLite with a cached context.
func GetCtx ¶
func GetCtx(ctx context.Context) ContextSQLite
GetCtx extracts the SQLite from context and wraps it as ContextSQLite, panics if not found.
type SQLite ¶
type SQLite interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
SQLite describes the sqlite module (a subset of *sql.DB).