asql

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 15 Imported by: 0

README

A-SQL

PostgreSQL utils collection.

go get -u github.com/a-novel-kit/asql

GitHub Actions Workflow Status codecov

GitHub repo file or directory count GitHub code size in bytes

Coverage graph

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDiscoverMigrations  = errors.New("failed to discover migrations")
	ErrCreateMigrator      = errors.New("failed to create migrator")
	ErrApplyMigrations     = errors.New("failed to apply migrations")
	ErrGetMigrationsStatus = errors.New("failed to get migrations status")
)

Functions

func Migrate

func Migrate(database *bun.DB, sqlMigrations embed.FS, logger quicklog.Logger) 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 cleaning function, whose execution can be deferred for a graceful shutdown.

func RegisterSortDirection

func RegisterSortDirection(customValidator *validator.Validate)

RegisterSortDirection registers the SortDirection type with a validator.

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
mocks

Jump to

Keyboard shortcuts

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