...
Tawesoft Logo

Package sqlite3

import "tawesoft.co.uk/go/sqlp/sqlite3"
Overview
Index

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

Constants

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

Variables

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

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

Utf8Collation is a common Collation provided as a convenience

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

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.

type Collation

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

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

type Config

Config can be used to configure the SQLite connection

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
}

type JournalMode

JournalMode is a type of SQLite journal mode

type JournalMode string