db

package
v0.0.0-...-c493d5c Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BulkInsert

func BulkInsert[T Table](executor gorp.SqlExecutor, db DB, allObjs ...T) error

Bulk insert objects into the database, using an executor which can be a transaction or a database connection itself.

Note: This function does NOT support auto-incrementing primary keys.

func ReplaceAll

func ReplaceAll[T Table](db DB, objs ...T) error

Replace all old objects of a table with new objects.

Types

type DB

type DB struct {
	*gorp.DbMap
}

Wrapper around gorp.DbMap that adds some convenience functions.

func NewPostgresDB

func NewPostgresDB(c conf.DBConfig, registry *monitoring.Registry) DB

Create a new postgres database and wait until it is connected.

func (*DB) AddTable

func (d *DB) AddTable(t Table) *gorp.TableMap

Adds a Model table to the database.

func (*DB) CheckLivenessPeriodically

func (d *DB) CheckLivenessPeriodically()

Check periodically if the database is alive. If not, panic.

func (*DB) Close

func (d *DB) Close()

Convenience function to close the database connection.

func (*DB) CreateTable

func (d *DB) CreateTable(table ...*gorp.TableMap) error

Adds missing functionality to gorp.DbMap which creates one table.

func (*DB) TableExists

func (d *DB) TableExists(t Table) bool

Check if a table exists in the database.

type Migrater

type Migrater interface {
	Migrate(bool)
}

func NewMigrater

func NewMigrater(db DB) Migrater

Create a new migrater with files embedded in the binary.

type Migration

type Migration struct {
	FileName string `db:"file_name"`
}

Migration model to keep track which migrations have been executed.

func (Migration) TableName

func (Migration) TableName() string

Table under which the migration model will be stored.

type Table

type Table interface {
	TableName() string
}

Jump to

Keyboard shortcuts

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