dsn

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 3 Imported by: 0

README

DSN Generator

Generate correct connection strings for mattn/go-sqlite3.

Usage

package main

import (
	"database/sql"
	"log"

	_ "github.com/mattn/go-sqlite3"
	"github.com/simonward87/dsn"
)

func main() {
	db, err := sql.Open("sqlite3", dsn.SQLite("db.sqlite3", dsn.Options{
		BusyTimeout: 10_000,
		ForeignKeys: true,
		JournalMode: dsn.JournalModeWal,
		Synchronous: dsn.SynchronousNormal,
	}))
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// TODO: database stuff
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SQLite

func SQLite(file string, opts Options) string

SQLite generates and returns a connection string for mattn/go-sqlite3 driver, using a file name and an Options object.

Types

type AutoVaccuum

type AutoVaccuum int

AutoVaccuum represents all possible values for PRAGMA auto_vaccuum

const (
	AutoVaccuumNone AutoVaccuum = iota
	AutoVaccuumFull
	AutoVaccuumIncremental
)

func (AutoVaccuum) String

func (av AutoVaccuum) String() string

type JournalMode

type JournalMode int

JournalMode represents all possible values for PRAGMA journal_mode

const (
	JournalModeDelete JournalMode = iota
	JournalModeTruncate
	JournalModePersist
	JournalModeMemory
	JournalModeWal
	JournalModeOff
)

func (JournalMode) String

func (jm JournalMode) String() string

type LockingMode

type LockingMode int

LockingMode represents all possible values for PRAGMA locking_mode

const (
	LockingModeNormal LockingMode = iota
	LockingModeExclusive
)

func (LockingMode) String

func (lm LockingMode) String() string

type Mode

type Mode int

Mode represents all possible values for SQLite open access mode

const (
	ModeRO Mode = iota
	ModeRW
	ModeRWC
	ModeMemory
)

func (Mode) String

func (m Mode) String() string

type MutexLocking

type MutexLocking int

MutexLocking represents all possible values for mutex mode

const (
	MutexLockingNo MutexLocking = iota
	MutexLockingFull
)

func (MutexLocking) String

func (ml MutexLocking) String() string

type Options

type Options struct {
	AutoVacuum             AutoVaccuum      `url:"_auto_vacuum,omitempty"`
	BusyTimeout            int              `url:"_busy_timeout,omitempty"`
	CacheSize              int              `url:"_cache_size,omitempty"`
	CaseSensitiveLike      bool             `url:"_case_sensitive_like,omitempty"`
	DeferForeignKeys       bool             `url:"_defer_foreign_keys,omitempty"`
	ForeignKeys            bool             `url:"_foreign_keys,omitempty"`
	IgnoreCheckConstraints bool             `url:"_ignore_check_constraints,omitempty"`
	Immutable              bool             `url:"immutable,omitempty"`
	JournalMode            JournalMode      `url:"_journal_mode,omitempty"`
	LockingMode            LockingMode      `url:"_locking_mode,omitempty"`
	Mode                   Mode             `url:"mode,omitempty"`
	MutexLocking           MutexLocking     `url:"_mutex,omitempty"`
	QueryOnly              bool             `url:"_query_only,omitempty"`
	RecursiveTriggers      bool             `url:"_recursive_triggers,omitempty"`
	SecureDelete           any              `url:"_secure_delete,omitempty"`
	SharedCacheMode        SharedCacheMode  `url:"cache,omitempty"`
	Synchronous            Synchronous      `url:"_synchronous,omitempty"`
	TimeZoneLocation       TimeZoneLocation `url:"_loc,omitempty"`
	TransactionLock        TransactionLock  `url:"_txlock,omitempty"`
	UACrypt                UACrypt          `url:"_auth_crypt,omitempty"`
	UAPassword             string           `url:"_auth_pass,omitempty"`
	UASalt                 string           `url:"_auth_salt,omitempty"`
	UAUsername             string           `url:"_auth_user,omitempty"`
	WritableSchema         bool             `url:"_writable_schema,omitempty"`
}

Options represents all currently available options when generating a connection string with function SQLite.

type SharedCacheMode

type SharedCacheMode int

SharedCacheMode represents all possible values for SQLite shared cache mode

const (
	SharedCacheModeShared SharedCacheMode = iota
	SharedCacheModePrivate
)

func (SharedCacheMode) String

func (scm SharedCacheMode) String() string

type Synchronous

type Synchronous int

Synchronous represents all possible values for PRAGMA synchronous

const (
	SynchronousOff Synchronous = iota
	SynchronousNormal
	SynchronousFull
	SynchronousExtra
)

func (Synchronous) String

func (s Synchronous) String() string

type TimeZoneLocation

type TimeZoneLocation int

TimeZoneLocation represents all possible values for time zone location

const (
	TimeZoneLocationAuto TimeZoneLocation = iota
)

func (TimeZoneLocation) String

func (tzl TimeZoneLocation) String() string

type TransactionLock

type TransactionLock int

TransactionLock represents all possible values for transaction locking behaviour

const (
	TransactionLockImmediate TransactionLock = iota
	TransactionLockDeferred
	TransactionLockExclusive
)

func (TransactionLock) String

func (tl TransactionLock) String() string

type UACrypt

type UACrypt int

UACrypt represents all possible values for user authentication module option crypt

const (
	UACryptSHA1 UACrypt = iota
	UACryptSSHA1
	UACryptSHA256
	UACryptSSHA256
	UACryptSHA384
	UACryptSSHA384
	UACryptSHA512
	UACryptSSHA512
)

func (UACrypt) String

func (c UACrypt) String() string

Jump to

Keyboard shortcuts

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