database

package
v0.0.1-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Builder = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)

Builder is a global instance of the sql builder. we are able to hardcode to postgres since sqlite3 is compatible with postgres.

Functions

func Connect

func Connect(ctx context.Context, driver string, datasource string) (*sqlx.DB, error)

Connect to a database and verify with a ping.

func ConnectAndMigrate

func ConnectAndMigrate(ctx context.Context, driver string, datasource string, migrator Migrator) (*sqlx.DB, error)

ConnectAndMigrate creates the database handle and migrates the database.

func Limit

func Limit(size int) uint64

limit returns the page size to a sql limit.

func Must

func Must(db *sqlx.DB, err error) *sqlx.DB

Must is a helper function that wraps a call to Connect and panics if the error is non-nil.

func Offset

func Offset(page, size int) uint64

offset converts the page to a sql offset.

func ProcessSQLErrorf

func ProcessSQLErrorf(ctx context.Context, err error, format string, args ...interface{}) error

Logs the error and message, returns either the provided message. Always logs the full message with error as warning.

Types

type Config

type Config struct {
	Driver     string
	Datasource string
}

Config specifies the config for the database package.

type Migrator

type Migrator func(ctx context.Context, dbx *sqlx.DB) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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