litemigrate

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MPL-2.0-no-copyleft-exception Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package litemigrate implements sqlmigrate.Migrator for SQLite using database/sql. The caller imports the driver:

import _ "modernc.org/sqlite"

db, err := sql.Open("sqlite", "app.db?_pragma=foreign_keys(1)")
conn, err := db.Conn(ctx)

SQLite disables foreign key enforcement by default. The _pragma DSN parameter enables it on every connection the pool opens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

type Migrator struct {
	Conn *sql.Conn
}

Migrator implements sqlmigrate.Migrator using a *sql.Conn with SQLite.

func New

func New(conn *sql.Conn) *Migrator

New creates a Migrator from the given connection. Use db.Conn(ctx) to obtain a *sql.Conn from a *sql.DB.

func (*Migrator) Applied

func (m *Migrator) Applied(ctx context.Context) ([]sqlmigrate.Migration, error)

Applied returns all applied migrations from the _migrations table. Returns an empty slice if the table does not exist.

We probe sqlite_master first rather than catching the SELECT error. SQLite returns the generic SQLITE_ERROR code (1) for "no such table", which is too coarse to distinguish from other errors via the typed driver error. The probe lets us use errors.Is(sql.ErrNoRows) instead of string-matching the error message.

func (*Migrator) ExecDown

func (m *Migrator) ExecDown(ctx context.Context, mig sqlmigrate.Migration, sql string) error

ExecDown runs the down migration SQL inside a transaction.

func (*Migrator) ExecUp

func (m *Migrator) ExecUp(ctx context.Context, mig sqlmigrate.Migration, sql string) error

ExecUp runs the up migration SQL inside a transaction.

Jump to

Keyboard shortcuts

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