Documentation
¶
Overview ¶
Package sqlitemigration provides a connection pool type that guarantees a series of SQL scripts has been run once successfully before making connections available to the application. This is frequently useful for ensuring tables are created.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnPrepareFunc ¶
A ConnPrepareFunc is called for each connection in a pool to set up connection-specific state. It must be safe to call from multiple goroutines.
If the ConnPrepareFunc returns an error, then it will be called the next time the connection is about to be used. Once ConnPrepareFunc returns nil for a given connection, it will not be called on that connection again.
type Options ¶
type Options struct {
// Flags is interpreted the same way as the argument to sqlitex.Open.
Flags sqlite.OpenFlags
// PoolSize sets an explicit size to the pool. If less than 1, a reasonable
// default is used.
PoolSize int
// OnStartMigrate is called after the pool has successfully opened a
// connection to the database but before any migrations have been run.
OnStartMigrate SignalFunc
// OnReady is called after the pool has connected to the database and run any
// necessary migrations.
OnReady SignalFunc
// OnError is called when the pool encounters errors while applying the
// migration. This is typically used for logging errors.
OnError ReportFunc
// PrepareConn is called for each connection in the pool to set up functions
// and other connection-specific state.
PrepareConn ConnPrepareFunc
}
Options specifies optional behaviors for the pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of SQLite connections.
func (*Pool) CheckHealth ¶
CheckHealth returns an error if the migration has not completed. Closed pools may report healthy.
func (*Pool) Close ¶
Close closes all connections in the Pool, potentially interrupting a migration.
type ReportFunc ¶
type ReportFunc func(error)
A ReportFunc is called for transient errors the pool encounters while running the migrations. It must be safe to call from multiple goroutines.
type Schema ¶
type Schema struct {
// AppID is saved to the database file to identify the application.
// It's used to prevent opening database files for a different
// application. It should be a positive number, but should not change
// between runs of the same program. A common way of setting this is with
// a compile-time constant that was randomly generated.
AppID int32
// Migrations is a list of SQL scripts to run. Each script is wrapped in a
// transaction which is rolled back on any error.
Migrations []string
// RepeatableMigration is a SQL script to run if any migrations ran. The
// script is wrapped in a transaction which is rolled back on any error.
RepeatableMigration string
}
Schema defines the migrations for the application.
type SignalFunc ¶
type SignalFunc func()
A SignalFunc is called at most once when a particular event in a Pool's lifecycle occurs.