sqlite3

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: BSD-3-Clause, MIT, MIT-0, + 2 more Imports: 5 Imported by: 0

README

sqlp/sqlite3 - SQLite3 database extras

go get -u "tawesoft.co.uk/go"
import "tawesoft.co.uk/go/sqlp/sqlite3"
Links License Stable?
homedocssrc MIT candidate

About

Package sqlite enchances a mattn/go-sqlite3 database with simple setup of things like utf8 collation and tawesoft.co.uk/go/sqlp features.

Getting Help

This package is part of tawesoft.co.uk/go, a monorepo for small Go modules maintained by Tawesoft®. Check out that URL for more information about other Go modules from Tawesoft plus community and commercial support options.

Documentation

Overview

Package sqlite enchances a mattn/go-sqlite3 database with simple setup of things like utf8 collation and tawesoft.co.uk/go/sqlp features.

Package Information

License: MIT (see LICENSE.txt)

Stable: candidate

For more information, documentation, source code, examples, support, links, etc. please see https://www.tawesoft.co.uk/go and https://www.tawesoft.co.uk/go/sqlp/sqlite3

Index

Constants

View Source
const (
	JournalModeDelete   = JournalMode("DELETE")
	JournalModeTruncate = JournalMode("TRUNCATE")
	JournalModePersist  = JournalMode("PERSIST")
	JournalModeMemory   = JournalMode("MEMORY")
	JournalModeWAL      = JournalMode("WAL")
	JournalModeOff      = JournalMode("OFF")
)

Variables

View Source
var Features = sqlp.Features{
	EscapeIdentifier:        escapeIdentifier,
	EscapeString:            escapeString,
	IsUniqueConstraintError: isUniqueConstraintError,
}

Features implements tawesoft.co.uk/go/dev/sqlp features for SQLite3

View Source
var Utf8Collation = Collation{"utf8", strings.Compare}

Utf8Collation is a common Collation provided as a convenience

Functions

func Open

func Open(driverName string, dataSource string, config Config) (*sql.DB, error)

Open opens/creates an SQLite database with pragmas from config

DriverName should match the name used in Register (or leave blank for default)

DataSource is the sqlite connection string e.g. "file:/var/sqlite/example.sql" or ":memory:"

func Opener

func Opener(config Config) func(string, string) (*sql.DB, error)

Opener returns an Open function with the config argument already applied

func Register

func Register(driverName string, collations []Collation, extensions []interface{})

Register creates a new Sqlite3 database driver named DriverName (e.g. "sqlite3_withCollations") that implements the given Collations and Extensions.

Currently extensions is a placeholder argument and is not implemented.

Must only be called once with a given driverName, otherwise Go will panic.

Types

type Collation

type Collation struct {
	Name string
	Cmp  func(string, string) int
}

A Collation is a names and a collation-aware string comparison function

type Config

type Config struct {
	// ForeignKeys enables/disables the SQLite foreign_keys pragma
	ForeignKeys bool

	// SecureDelete enables/disables the SQLite secure_delete pragma
	SecureDelete bool

	// JournalMode, defaults to JournalModeWAL
	JournalMode JournalMode
}

Config can be used to configure the SQLite connection

type JournalMode

type JournalMode string

JournalMode is a type of SQLite journal mode

Jump to

Keyboard shortcuts

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