Help us shape the future of Go! Take the 2026 Go Developer Survey

relational

package
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package relational provides the shared Connection and Transaction classes used by the database plugins (sqlite, sql). Both plugins expose the same surface — connect(...) -> Connection with query/execute/begin/close — so scripts written against one backend work unchanged against the other.

Index

Constants

This section is empty.

Variables

View Source
var (
	SQLiteSpec = DialectSpec{
		ILike:     "like",
		TablesSQL: "select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name",
	}
	MySQLSpec = DialectSpec{
		Backtick:   true,
		ILike:      "like",
		TablesSQL:  "select table_name as name from information_schema.tables where table_schema = database() and table_type = 'BASE TABLE' order by table_name",
		ColumnsSQL: "select column_name as name from information_schema.columns where table_schema = database() and table_name = ? order by ordinal_position",
	}
	PostgresSpec = DialectSpec{
		Numbered:   true,
		ILike:      "ilike",
		TablesSQL:  "select table_name as name from information_schema.tables where table_schema = current_schema() and table_type = 'BASE TABLE' order by table_name",
		ColumnsSQL: "select column_name as name from information_schema.columns where table_schema = current_schema() and table_name = ? order by ordinal_position",
	}
)

SQLiteSpec, MySQLSpec and PostgresSpec are the known dialects; a plugin serving one driver bakes its spec in, and the sql plugin picks per connection from the DSN scheme.

View Source
var ScriptKitSource = strings.ReplaceAll(scriptKitRaw, "§", "`")

ScriptKitSource is the shared ORM script, backticks restored.

Functions

func ConnectionClass

func ConnectionClass(constructor interface{}) *object.ClassBuilder

ConnectionClass builds the Connection class. constructor is the plugin-specific typed constructor (e.g. sqlite's opens a file, sql's parses a DSN); it must return (*Conn, error). Scripts construct the class directly — Connection(path) — or through each plugin's connect() helper.

func ConnectionScriptSource

func ConnectionScriptSource(pluginName string, spec DialectSpec) string

ConnectionScriptSource returns the Connection class a single-driver plugin registers in external mode: a script-defined wrapper whose methods proxy to the plugin object, with get_orm() returning the host-side kit carrying the plugin's baked dialect. TransactionScriptSource is its transaction half.

func ConnectionScriptSourceMultiDriver

func ConnectionScriptSourceMultiDriver(pluginName string) string

ConnectionScriptSourceMultiDriver is the external-mode wrapper for a plugin serving several drivers (the sql plugin): the dialect is picked from the DSN scheme at connect time, host-side, since the wrapper sees the DSN before the plugin does. TransactionScriptSourceMultiDriver is its transaction half.

func CursorClass

func CursorClass() *object.ClassBuilder

CursorClass builds the Cursor class handed out by query_iter.

func ScriptModuleSource

func ScriptModuleSource(twinName string, singleDriver bool, spec DialectSpec) string

ScriptModuleSource returns the full user-facing module for compiled-in registration: the native twin carries the connection; this wrapper adds begin(), get_orm() and the shared kit. twinName is the native library name ("scriptling._sqlite"). singleDriver bakes the spec in; a multi-driver plugin (sql) sniffs the DSN scheme instead.

func TransactionClass added in v0.24.2

func TransactionClass() *object.ClassBuilder

TransactionClass builds the Transaction class handed out by begin. Transactions come from conn.begin(); the constructor refuses direct use.

func TransactionScriptSource added in v0.24.2

func TransactionScriptSource(pluginName string, spec DialectSpec) string

TransactionScriptSource is the external-mode Transaction wrapper for a single-driver plugin: it proxies to the plugin-side transaction object the remote begin() handed back, and get_orm() binds the host-side kit to it so ORM calls join the transaction.

func TransactionScriptSourceMultiDriver added in v0.24.2

func TransactionScriptSourceMultiDriver(pluginName string) string

TransactionScriptSourceMultiDriver is the external-mode Transaction wrapper for the sql plugin: same renumbering as its Connection, since the transaction's statements carry ? placeholders on the postgres half.

Types

type Conn

type Conn struct {
	DB *sql.DB
	// SingleConn marks a database served by exactly one pooled connection (a
	// private in-memory SQLite). While a transaction or an open cursor holds
	// that connection the pool is exhausted, so connection-level calls would
	// block forever on it; they fail fast with a clear error instead. A
	// pooled database can serve several at once, so it leaves the flag unset.
	SingleConn bool
	// contains filtered or unexported fields
}

Conn is the typed receiver holding the live database handle. It is nothing but the driver: query/execute/begin/close. Everything backend-specific above that — placeholder translation, quoting, the ORM — lives in the script-side kit the plugin's Connection wrapper hands out.

type Cursor

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

Cursor streams rows from one query without materialising the result. A single consumer drains it: next() returns each row as a dict, then None forever once exhausted. close() releases the underlying rows; __del__ makes abandoned cursors release them too.

type DialectSpec

type DialectSpec struct {
	Numbered  bool
	Backtick  bool
	ILike     string
	TablesSQL string
	// ColumnsSQL reads a table's column names (as "name", in table order)
	// with the table name bound as one parameter. Empty means the dialect
	// cannot parameterize it and uses SQLite's PRAGMA table_info instead.
	ColumnsSQL string
}

DialectSpec is the baked-in dialect a plugin's ORM carries: placeholder numbering, identifier quoting, the case-insensitive LIKE word, and the catalogue query behind tables(). With this, the native side of a plugin is nothing but the driver — query/execute/close.

type ScriptEntry

type ScriptEntry struct {
	Name   string
	Source string
	Class  bool
}

ScriptEntry is one function or class the plugin registers as script source. External mode registers each entry so the host's generated module carries them; compiled-in mode concatenates them into one module.

func ScriptKitEntries

func ScriptKitEntries() []ScriptEntry

ScriptKitEntries decomposes the kit into per-name registrations. Each source already carries its full def/class header, so the entries emit verbatim into a generated module (external mode) or concatenate (compiled-in mode).

type Tx added in v0.24.2

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

Tx is the typed receiver holding one open transaction: the same query/execute surface as Conn, plus commit and rollback.

Jump to

Keyboard shortcuts

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