sqlite3

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Overview

Package sqlite3 implements the sq driver for SQLite. The backing SQL driver is mattn/sqlite3.

Index

Constants

View Source
const (

	// Prefix is the scheme+separator value "sqlite3://".
	Prefix = "sqlite3://"
)

Variables

This section is empty.

Functions

func DBTypeForKind

func DBTypeForKind(knd kind.Kind) string

DBTypeForKind returns the database type for kind. For example: Int --> INTEGER.

func MungeLocation added in v0.23.0

func MungeLocation(loc string) (string, error)

MungeLocation takes a location argument (as received from the user) and builds a sqlite3 location URL. Each of these forms are allowed:

sqlite3:///path/to/sakila.db	--> sqlite3:///path/to/sakila.db
sqlite3:sakila.db 						--> sqlite3:///current/working/dir/sakila.db
sqlite3:/sakila.db 						--> sqlite3:///sakila.db
sqlite3:./sakila.db 					--> sqlite3:///current/working/dir/sakila.db
sqlite3:sakila.db 						--> sqlite3:///current/working/dir/sakila.db
sakila.db											--> sqlite3:///current/working/dir/sakila.db
/path/to/sakila.db						--> sqlite3:///path/to/sakila.db

An optional "?key=val[&...]" connection-string suffix is preserved verbatim. The first '?' is always treated as the path/query separator, so paths whose POSIX filename legally contains '?' are not supported.

The final form is particularly nice for shell completion etc.

Note that this function is OS-dependent, due to the use of pkg filepath. Thus, on Windows, this is seen:

C:/Users/sq/sakila.db 				--> sqlite3://C:/Users/sq/sakila.db

But that input location gets mangled on non-Windows OSes. This probably isn't a problem in practice, but longer-term it may make sense to rewrite MungeLocation to be OS-independent.

MungeLocation is idempotent, and is a thin wrapper around location.MungeTemplateForDriver: the user-typed location is a placeholder template, so cwd bytes spliced in by absolutization are escaped (gh #797). Locations resolved from secret placeholders at connect time are literal bytes and take the no-escape path via location.MungeForDriver (driver.ResolveSourceSecrets).

func NewScratchSource

func NewScratchSource(ctx context.Context, fpath string) (src *source.Source, clnup func() error, err error)

NewScratchSource returns a new scratch src. The supplied fpath must be the absolute path to the location to create the SQLite DB file, typically in the user cache dir. The returned clnup func will delete the dB file.

func PathFromLocation

func PathFromLocation(src *source.Source) (string, error)

PathFromLocation returns the absolute file path from the source location, which must have the "sqlite3://" prefix. Any "?key=val&..." connection-string suffix is stripped; callers that need the full DSN should use dsnFromLocation instead.

Types

type Provider

type Provider struct {
	Log *slog.Logger
}

Provider is the SQLite3 implementation of driver.Provider.

func (*Provider) DriverFor

func (p *Provider) DriverFor(typ drivertype.Type) (driver.Driver, error)

DriverFor implements driver.Provider.

Directories

Path Synopsis
Package sqlparser contains SQL parsing functionality for SQLite.
Package sqlparser contains SQL parsing functionality for SQLite.

Jump to

Keyboard shortcuts

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