database

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2022 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMigrationNeeded indicates that a database migration is needed
	// before the database can be initialized
	ErrMigrationNeeded = errors.New("database migration required")

	// ErrDatabaseNotInitialized indicates that the database is not
	// initialized, usually due to an incomplete configuration.
	ErrDatabaseNotInitialized = errors.New("database not initialized")
)
View Source
var DB *sqlx.DB
View Source
var WriteMu sync.Mutex

Functions

func AppSchemaVersion added in v0.2.0

func AppSchemaVersion() uint

func Backup added in v0.2.0

func Backup(db *sqlx.DB, backupPath string) error

Backup the database. If db is nil, then uses the existing database connection.

func Close added in v0.10.0

func Close() error

func DatabaseBackupPath added in v0.2.0

func DatabaseBackupPath() string

func DatabasePath added in v0.7.0

func DatabasePath() string

func Initialize

func Initialize(databasePath string) error

Initialize initializes the database. If the database is new, then it performs a full migration to the latest schema version. Otherwise, any necessary migrations must be run separately using RunMigrations. Returns true if the database is new.

func NeedsMigration added in v0.2.0

func NeedsMigration() bool

Migrate the database

func Ready added in v0.7.0

func Ready() error

Ready returns an error if the database is not ready to begin transactions.

func Reset

func Reset(databasePath string) error

func RestoreFromBackup added in v0.2.0

func RestoreFromBackup(backupPath string) error

func RunMigrations added in v0.2.0

func RunMigrations() error

Migrate the database

func Version added in v0.2.0

func Version() uint

func WithTxn added in v0.4.0

func WithTxn(fn func(tx *sqlx.Tx) error) error

WithTxn executes the provided function within a transaction. It rolls back the transaction if the function returns an error, otherwise the transaction is committed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL