database

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

README

database

database interaction untilities

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(query string, parameters ...driver.Value) func() *Options

func Named

func Named(name string) func() *Options

func QueryRecord

func QueryRecord[Shape any](database Database, tx *sql.Tx, query string, params ...any) (*Shape, error)

func QueryRecords

func QueryRecords[Shape any](database Database, tx *sql.Tx, query string, params ...any) ([]*Shape, error)

func Record

func Record[Record any](rows *sql.Rows) (*Record, error)

func Records

func Records[Record any](rows *sql.Rows) ([]*Record, error)

func Tx

func Tx[A any](database Database, handler func(*sql.Tx) (*A, error)) (*A, error)

func TxStub

func TxStub(database Database, handler func(*sql.Tx) error) error

func WithFunc

func WithFunc(name string, impl any) func() *Options

Types

type Database

type Database interface {
	Migrator

	Name() string
	Query(tx *sql.Tx, query string, args ...any) (*sql.Rows, error)
	Exec(tx *sql.Tx, query string, args ...any) (sql.Result, error)
	Close(ctx context.Context) error
	// contains filtered or unexported methods
}

func Sqlite

func Sqlite(connectionString string, options ...func() *Options) (Database, error)

type Migrator

type Migrator interface {
	Migrate(files VirtualFS) error
}

type Options

type Options struct {
	Name  string
	Funcs map[string]any
	Inits []Statement
}

func (*Options) DriverName

func (o *Options) DriverName(connectionString string) (string, error)

type Query

type Query string

func (Query) LogValue

func (q Query) LogValue() slog.Value

type Statement

type Statement struct {
	Query      string
	Parameters []driver.Value
}

type VirtualFS

type VirtualFS interface {
	ReadDir(name string) ([]fs.DirEntry, error)
	ReadFile(name string) ([]byte, error)
}

Jump to

Keyboard shortcuts

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