quicksqlite

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 14 Imported by: 0

README

quicksqlite

Quick setup of modernc.org/sqlite and golang-migrate with sensible defaults.

Documentation

Overview

Package quicksqlite makes it trivial to spin-up a robust SQLite database connection with sensible production-grade defaults.

Index

Constants

This section is empty.

Variables

View Source
var ReadOnly = baseConfig.WithParamsMerged(Params{
	"mode": []string{"ro"},
	"_pragma": []string{
		"query_only=true",
	},
})

ReadOnly is a configuration with sensible defaults for read-only connections.

View Source
var ReadWrite = baseConfig.WithMaxOpenConns(1).WithParamsMerged(Params{
	"mode":    []string{"rwc"},
	"_txlock": []string{"immediate"},
})

ReadWrite is a configuration with sensible defaults for read-write connections.

Functions

This section is empty.

Types

type Config

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

Config is a configuration for connecting to SQLite databases.

func (Config) Connect

func (c Config) Connect(ctx context.Context, dataSourceName string) (*sql.DB, error)

Connect creates a new SQLite database connection with the provided data source name.

func (Config) ConnectInMemory

func (c Config) ConnectInMemory(ctx context.Context) (*sql.DB, error)

ConnectInMemory creates a new SQLite database in memory.

func (Config) WithLogger

func (c Config) WithLogger(log *slog.Logger) Config

WithLogger sets the logger to use for database migrations.

func (Config) WithMaxOpenConns

func (c Config) WithMaxOpenConns(n int) Config

WithMaxOpenConns sets the maximum number of open connections to the database. See sql.DB.SetMaxOpenConns for the exact behavior.

func (Config) WithMigrations

func (c Config) WithMigrations(fsys fs.FS) Config

WithMigrations sets the file system to use for database migrations.

func (Config) WithMigrationsInPath

func (c Config) WithMigrationsInPath(fsys fs.FS, path string) Config

WithMigrationsInPath sets the file system and path to use for database migrations.

func (Config) WithParamsMerged

func (c Config) WithParamsMerged(params ...Params) Config

WithParamsMerged merges the provided parameters with the existing parameters.

type Params

type Params url.Values

Params is a map of SQLite connection parameters.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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