db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package db provides small database/sql helpers for nullable values, SQLite constraint checks, migrations, transactions, and query tracing.

Index

Constants

View Source
const TracedDriverName = "sqlite3-traced"

TracedDriverName is the database/sql driver name registered by RegisterTracedDriver.

Variables

This section is empty.

Functions

func BoolToInt

func BoolToInt(b bool) int64

BoolToInt returns 1 for true and 0 for false.

func FloatOrZero

func FloatOrZero(v sql.NullFloat64) float64

FloatOrZero returns the float64 value of a sql.NullFloat64 or zero if it's null.

func Int64OrZero

func Int64OrZero(v sql.NullInt64) int64

Int64OrZero returns the int64 value of a sql.NullInt64 or zero if it's null.

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation returns true if the error is a SQLite UNIQUE constraint violation.

func Migrate

func Migrate(ctx context.Context, db *sql.DB, dir fs.FS) error

Migrate applies SQL migrations from dir/migrations in ascending version order.

func NullJoined

func NullJoined(xs []string) sql.NullString

NullJoined returns a NullString by joining xs with commas. Returns an invalid NullString if xs is empty.

func NullableFloat

func NullableFloat(v float64) sql.NullFloat64

NullableFloat returns a valid sql.NullFloat64 when v is non-zero.

func RegisterTracedDriver

func RegisterTracedDriver(tr *Tracer)

RegisterTracedDriver registers the traced SQLite driver once per process.

Types

type Tracer

type Tracer struct {
	SlowThresh  time.Duration // 0 = off
	MaskArgs    bool
	SampleEvery int // 0/1 => all; N => 1/N
}

Tracer configures query tracing for the wrapped SQLite driver.

Jump to

Keyboard shortcuts

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