sqlstore

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 11 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 sqlstore implements storage.Store on database/sql. A driver supplies a Dialect: its schema migrations and the few behaviours that differ between databases. The SQL it issues is portable across SQLite, PostgreSQL and MySQL; times are stored as Unix microseconds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IgnoreSuffix

func IgnoreSuffix(insert string) string

IgnoreSuffix is InsertIgnore for databases with ON CONFLICT DO NOTHING.

Types

type Dialect

type Dialect struct {
	// Migrations holds *.sql files applied in name order, each once.
	// Statements are separated by ";" at the end of a line.
	Migrations fs.FS
	// Numbered placeholders ($1, $2, ...) instead of "?".
	Numbered bool
	// InsertIgnore turns an INSERT into one that skips rows violating a
	// unique constraint.
	InsertIgnore func(insert string) string
	// Conflict reports errors that mean a concurrent change won: unique
	// violations, deadlocks, serialization failures, busy databases.
	Conflict func(error) bool
	// Lock, if set, serialises migrations across instances on conn.
	Lock func(ctx context.Context, conn *sql.Conn) (unlock func(), err error)
}

Dialect describes a database.

type Store

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

func New

func New(ctx context.Context, db *sql.DB, d Dialect) (*Store, error)

New migrates db and returns a store on it.

func (*Store) Close

func (s *Store) Close() error

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying database, for tests and tools.

func (*Store) Tx

func (s *Store) Tx(ctx context.Context, fn func(storage.Tx) error) error

Jump to

Keyboard shortcuts

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