sqlite

package
v0.0.0-...-59b3aaa Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sqlite implements the SQLite dialect driver (Tier 2). This file is the lexer profile: token boundaries only, no SQL understanding.

Index

Constants

View Source
const (
	TypeInteger uint32 = 1
	TypeReal    uint32 = 2
	TypeText    uint32 = 3
	TypeBlob    uint32 = 4
	TypeNumeric uint32 = 5
	TypeBool    uint32 = 6
	TypeTime    uint32 = 7
)

SQLite has no OIDs and no static column types — only declared types and affinity rules. dialect.TypeRef.OID carries one of the small codes below; TypeRef.Name keeps the normalized declared type for diagnostics. The encoding is stable — it is what the committed cache stores.

Variables

This section is empty.

Functions

func AffinityRef

func AffinityRef(decltype string) (dialect.TypeRef, bool)

AffinityRef classifies a declared column type per SQLite's affinity rules (https://sqlite.org/datatype3.html §3.1), with deliberate carve-outs for the conventional BOOLEAN and date/time declarations (numeric affinity in SQLite, but bool / time.Time is what Go callers want; drivers convert on scan). ok is false only for an empty declared type — an expression column, which needs a `-- @column` annotation.

Types

type Frontend

type Frontend struct{}

Frontend is the rqlite/sql-backed grammar frontend for SQLite: a pure-Go parser with byte offsets on every node (including relation names, unlike the TiDB AST). Known parser gaps versus the current SQLite grammar — RIGHT/FULL JOIN (3.39+) — surface as parse diagnostics; the real-engine oracle backstops everything the grammar accepts.

func (Frontend) Parse

func (Frontend) Parse(sqlText string) (dialect.Tree, error)

func (Frontend) ProbeExpr

func (f Frontend) ProbeExpr(expr string) error

ProbeExpr checks that expr forms exactly one boolean-position expression. Parenthesis balance is the rules' (lexer-level) concern.

func (Frontend) ProbeGroupBy

func (f Frontend) ProbeGroupBy(clause string) error

ProbeGroupBy checks that clause is exactly one statement-level GROUP BY clause and nothing more.

func (Frontend) ProbeInsertValue

func (f Frontend) ProbeInsertValue(expr string) error

ProbeInsertValue checks that expr is exactly one VALUES row item. (SQLite has no per-item DEFAULT keyword; it fails to parse, which is the correct dialect answer.)

func (Frontend) ProbeJoinItem

func (f Frontend) ProbeJoinItem(item string) error

ProbeJoinItem checks that item is a join item attachable to a preceding FROM entry.

func (Frontend) ProbeOrderBy

func (f Frontend) ProbeOrderBy(clause string) error

ProbeOrderBy checks that clause is exactly one statement-level ORDER BY clause and nothing more.

func (Frontend) ProbeOrderByKey

func (f Frontend) ProbeOrderByKey(expr string) error

ProbeOrderByKey checks that expr is exactly one sort key.

func (Frontend) ProbeSetItem

func (f Frontend) ProbeSetItem(item string) error

ProbeSetItem checks that item is exactly one UPDATE SET assignment.

type Oracle

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

Oracle is the sqlite3_prepare-backed type oracle over the in-process engine (ncruces/go-sqlite3: the real SQLite compiled to WASM, run under wazero — pure Go, nothing external). Preparing compiles the statement through SQLite's planner, so prepare alone is both the parse and the plan check; EXPLAIN QUERY PLAN adds the human-readable plan. Result columns are typed by declared type through the affinity rules; expression columns have no declared type (SQLite returns NULL) and stay zero-typed — the pipeline fills them from mandatory `-- @column` annotations. Parameter slots are never typed by SQLite; `-- @param` annotations are mandatory (Tier 2).

func NewOracle

func NewOracle(conn *sqlite3.Conn) *Oracle

func (*Oracle) Describe

func (o *Oracle) Describe(ctx context.Context, sql string) (dialect.Desc, error)

func (*Oracle) Plan

func (o *Oracle) Plan(ctx context.Context, sql string) error

Plan prepares EXPLAIN QUERY PLAN and steps it: preparing already runs SQLite's planner, stepping surfaces any late errors. Unbound parameters are NULL by SQLite's rules — no data is touched.

func (*Oracle) PlanText

func (o *Oracle) PlanText(ctx context.Context, sql string) (string, error)

PlanText returns the EXPLAIN QUERY PLAN detail rows.

func (*Oracle) ServerVersion

func (o *Oracle) ServerVersion(ctx context.Context) (string, error)

func (*Oracle) Snapshot

func (o *Oracle) Snapshot(ctx context.Context) (*cache.Catalog, error)

Snapshot dumps the main database's tables. SQLite has no OIDs; tables get stable synthetic ones (1-based in name order), and column att numbers are pragma cid+1.

type Profile

type Profile struct{}

func (Profile) InEmptySQL

func (Profile) InEmptySQL() string

InEmptySQL is the arity-0 @in emission (FALSE even for NULL operands; SQLite allows a FROM-less SELECT with WHERE).

func (Profile) NextToken

func (Profile) NextToken(src []byte, pos int) (dialect.Token, error)

func (Profile) PlaceholderStyle

func (Profile) PlaceholderStyle() dialect.PlaceholderStyle

PlaceholderStyle declares SQLite's '?' per-occurrence binding.

type TypeMap

type TypeMap struct{}

TypeMap maps encoded SQLite type refs to Go types for generated code.

func (TypeMap) GoType

func (TypeMap) GoType(oid uint32) (dialect.GoTypeRef, bool)

func (TypeMap) TypeByName

func (TypeMap) TypeByName(name string) (dialect.TypeRef, bool)

TypeByName resolves a `-- @param name: type` / `-- @column name: type` annotation — on SQLite the mandatory source of parameter types and of expression-column types. Length arguments are stripped; resolution then follows the affinity rules, so any declarable SQLite type name works.

Jump to

Keyboard shortcuts

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