database

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package database provides SQLite database helpers with WAL mode.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBuildConnectionURL = errors.New("failed to build SQLite connection URL")
	ErrOpenDatabase       = errors.New("failed to open database")
	ErrPingDatabase       = errors.New("failed to ping database")
	ErrApplySchema        = errors.New("failed to apply schema")
	ErrSchemaValidation   = errors.New("schema validation failed")
)

Database errors.

Functions

func BaseSchema

func BaseSchema() string

BaseSchema returns a minimal base schema for juango applications. Applications should extend this with their own tables.

func Migrate

func Migrate(db *Database, migrations embed.FS, dir string) error

Migrate runs migrations from an embedded filesystem. The migrations should be in a directory structure like: migrations/001_initial.sql, migrations/002_add_users.sql, etc.

func MigrateWithSquibble

func MigrateWithSquibble(db *Database, schema *squibble.Schema) error

MigrateWithSquibble runs migrations using squibble schema management.

Types

type Config

type Config struct {
	Path   string
	Schema string
}

Config holds database configuration.

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database wraps the sqlx database connection.

func New

func New(path string, schema string) (*Database, error)

New creates a new Database instance with the given path and schema.

func NewWithConfig

func NewWithConfig(cfg *sqliteconfig.Config, schema string) (*Database, error)

NewWithConfig creates a new Database with custom configuration.

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection.

func (*Database) DB

func (d *Database) DB() *sqlx.DB

DB returns the underlying *sqlx.DB for advanced operations.

func (*Database) WithTx

func (d *Database) WithTx(ctx context.Context, fn func(*sqlx.Tx) error) error

WithTx executes a function within a database transaction.

Directories

Path Synopsis
Package sqliteconfig provides type-safe configuration for SQLite databases with proper enum validation and URL generation for modernc.org/sqlite driver.
Package sqliteconfig provides type-safe configuration for SQLite databases with proper enum validation and URL generation for modernc.org/sqlite driver.

Jump to

Keyboard shortcuts

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