dbhelper

package module
v0.0.0-...-a66f317 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

package dbhelper implements functions to be able to easily create and modify database table structures without duplicating code.

Users of this package will define a set of migration functions which modify the database structure. The first migration will create the initial tables, the next ones will modify the tables. When the database migration function runs for the first time, it creates the database structure, on repeated runs, it will check if there are any migrations that should be ran and if they are there, runs them. This means that with one set of functions, we can initialize and migrate the database without any code duplication.

This package stores the database schema version in a table called _dbschema

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunDbVerMigrations

func RunDbVerMigrations(db *sql.DB, table, keyfield, key, valfield string) error

migrations for the dbver number to be used in case migrations were used previously and the program is switching to use dbhelper which uses a different internal table and different indexing

func RunMigrations

func RunMigrations(db *sql.DB, migrations []func(*sql.Tx) error) error

pass a list of functions that performs migrations, this package will find which ones are new by comparing the length of the migrations slice with the index of the migration that successfully ran last and run those that didn't run yet.

Types

This section is empty.

Jump to

Keyboard shortcuts

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