Documentation
¶
Overview ¶
Package sql is the network relational database plugin covering MySQL, MariaDB and PostgreSQL. Scripts import it as scriptling.sql:
import scriptling.sql as sql
conn = sql.connect("postgres://user:pass@host:5432/app")
conn.execute("create table t (id serial primary key, name text)")
conn.execute("insert into t (name) values (?)", "ada")
rows = conn.query("select * from t where name = ?", "ada")
tx = conn.begin()
tx.execute("insert into t (name) values (?)", "grace")
tx.commit()
conn.close()
The DSN scheme picks the driver: postgres:// or postgresql:// for PostgreSQL, mysql:// or mariadb:// for MySQL and MariaDB (both speak the MySQL protocol). The query/execute/begin/close surface is identical to the sqlite plugin; ? placeholders are translated to $n on PostgreSQL, which also accepts explicit $n. The server address must pass the host's network policy. The same library serves external plugin mode (plugins/sql/cmd) and compiled-in registration (build tag plugin_sql).
Index ¶
Constants ¶
const ConnectSource = `def connect(dsn):
return Connection(dsn)
`
ConnectSource is the scriptling-source wrapper for connect() in external plugin mode, where a Go function cannot return an instance over the wire: it constructs the Connection class through the plugin object protocol.
const Description = "MySQL, MariaDB and PostgreSQL client"
Description is the plugin metadata description.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(policy plugin.PolicySource) *object.Library
Build returns the scriptling.sql library. policy is read at call time so an external plugin sees the policy its handshake delivered.
func RegisterInProcess ¶
func RegisterInProcess(registrar interface {
RegisterLibrary(*object.Library)
RegisterScriptLibrary(name string, script string) error
}, policy *plugin.Policy)
RegisterInProcess registers both halves for embedders and tests.
func ScriptModule ¶
func ScriptModule() string
ScriptModule is the user-facing scriptling.sql module for compiled-in registration: the Connection wrapper (with get_orm) plus the shared ORM kit, importing the native twin.
Types ¶
This section is empty.