Documentation
¶
Overview ¶
Package relational provides the shared Connection class used by the database plugins (sqlite, sql). Both plugins expose the same surface — connect(...) -> Connection with query/execute/close — so scripts written against one backend work unchanged against the other.
Index ¶
- Variables
- func ConnectionClass(constructor interface{}) *object.ClassBuilder
- func ConnectionScriptSource(pluginName string, spec DialectSpec) string
- func ConnectionScriptSourceMultiDriver(pluginName string) string
- func CursorClass() *object.ClassBuilder
- func ScriptModuleSource(twinName string, singleDriver bool, spec DialectSpec) string
- type Conn
- type Cursor
- type DialectSpec
- type ScriptEntry
Constants ¶
This section is empty.
Variables ¶
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.
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.
func ConnectionScriptSourceMultiDriver ¶
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.
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 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.
Types ¶
type Conn ¶
Conn is the typed receiver holding the live database handle. It is nothing but the driver: query/execute/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 ¶
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).