database

package
v0.0.0-...-760d8ea Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: GPL-3.0 Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const TestDSN = "postgres://test:test@localhost:5432/test?sslmode=disable"

Variables

This section is empty.

Functions

func BeginTestTX

func BeginTestTX[T any](database bun.IDB, fixtures []T) bun.Tx

func ClearTestDB

func ClearTestDB(database *bun.DB)

func FreezeTime

func FreezeTime(db bun.IDB, date time.Time) error

func Migrate

func Migrate(database *bun.DB, sqlMigrations embed.FS, formatter formatters.Formatter) error

Migrate looks for non-applied migrations, and applies them to the database.

func MustRegisterValidation

func MustRegisterValidation(
	customValidator *validator.Validate, name string, validationFn func(fl validator.FieldLevel) bool,
)

func OpenDB

func OpenDB(dsn string) (*bun.DB, func(), error)

OpenDB automatically configures a bun.DB instance with postgresSQL drivers. It returns the database, along with a closing function, whose execution can be deferred for a graceful shutdown.

func OpenTestDB

func OpenTestDB(sqlMigrations *embed.FS) (*bun.DB, func(), error)

OpenTestDB opens a connection to a test DB.

The test DB must be available under the value stored in DSN.

func RegisterSortDirection

func RegisterSortDirection(customValidator *validator.Validate)

RegisterSortDirection registers the SortDirection type with a validator.

func RestoreTime

func RestoreTime(db bun.IDB) error

func RollbackTestTX

func RollbackTestTX(transaction bun.Tx)

func ValidateEnum

func ValidateEnum[T comparable](list ...T) func(fl validator.FieldLevel) bool

ValidateEnum creates a custom validation for go-validator. It checks if the value is part of the enum.

TODO: look for custom errors in v11: https://github.com/go-playground/validator/issues/669

Types

type SortDirection

type SortDirection string

SortDirection controls the direction of the ordering for a particular request. You can use this type with a validator.

const (
	SortDirectionNone SortDirection = ""
	SortDirectionAsc  SortDirection = "asc"
	SortDirectionDesc SortDirection = "desc"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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