Pure-Hot MySQL client. Speaks the MySQL client/server protocol
directly over ::hot::tcp (with optional ::hot::tls), so no
native driver is required. Supports caching_sha2_password (the
MySQL 8 default) and mysql_native_password authentication.
Parameterized statements always use the binary prepared-statement
protocol (? placeholders) — MySQL's text protocol has no safe
parameter binding. Use the ::sql package's mysql driver for
placeholder compilation, typed queries, and transactions.
Over plaintext TCP, caching_sha2_password can only complete when
the server has the account's credentials cached (fast auth). When
the server demands full authentication, connect errs with guidance:
enable ssl: true, or use a mysql_native_password account.
A connection is a single TCP socket with no request pipelining and is NOT safe for concurrent use. Hot runs independent expressions in parallel — do not share one connection across parallel branches or spawned tasks; open a connection per branch instead.
Example
conn ::mysql/connect({host: "localhost", user: "root", password: "secret", database: "app"})
rows ::mysql/query(conn, "SELECT id, name FROM users WHERE active = ?", [true])
::mysql/close(conn)
Values
COM-QUERY
COM-QUERY: Int 3
COM-QUIT
COM-QUIT: Int 1
COM-STMT-CLOSE
COM-STMT-CLOSE: Int 25
COM-STMT-EXECUTE
COM-STMT-EXECUTE: Int 23
COM-STMT-PREPARE
COM-STMT-PREPARE: Int 22
TYPE-BLOB
TYPE-BLOB: Int 252
TYPE-VAR-STRING
TYPE-VAR-STRING: Int 253
Functions
close
fn (conn: Map): Bool
Send COM_QUIT and close the socket. Safe to call more than once.
Example
conn ::mysql/connect({
host: "db.internal",
user: "app",
password: ::hot::ctx/get("mysql.password"),
database: "shop"
})
::mysql/query(conn, "SELECT 1")
::mysql/close(conn)
connect
fn (options: MySqlOptions | Map): Any
Connect and authenticate. Returns a connection (pass it to
query/execute/close), or an Err carrying
{code, sqlstate, message} for server-reported failures.
Example
conn ::mysql/connect({
host: "db.internal",
user: "app",
password: ::hot::ctx/get("mysql.password"),
database: "shop",
ssl: true,
tls: {ca-pem: ::hot::ctx/get("mysql.ca.pem")}
})
conn.server-version
::mysql/close(conn)
execute
fn (conn: Map, sql: Str): Any
fn (conn: Map, sql: Str, params: Vec): Any
Run a statement (INSERT/UPDATE/DELETE/DDL). Returns
{command, rows-affected, last-insert-id} or an Err. With params,
uses the binary prepared-statement protocol.
Example
conn ::mysql/connect({
host: "db.internal",
user: "app",
password: ::hot::ctx/get("mysql.password"),
database: "shop"
})
updated ::mysql/execute(conn, "UPDATE orders SET status = ? WHERE id = ?", ["shipped", 42])
updated.rows-affected
// No params: the text protocol
::mysql/execute(conn, "DELETE FROM carts WHERE expired = 1")
::mysql/close(conn)
query
fn (conn: Map, sql: Str): Any
fn (conn: Map, sql: Str, params: Vec): Any
Run a query. Without params, uses the text protocol (COM_QUERY);
with params, the binary prepared-statement protocol (?
placeholders only). Returns rows as Vec<Map> or an Err.
Bindable params: Int, Dec, Str, Bool (as 1/0), Bytes, and null — sent as VAR_STRING/BLOB and coerced by MySQL to the column type.
Column values decode by type and signedness: integers to Int (unsigned BIGINT above Int range promotes to an exact Dec), FLOAT/DOUBLE/DECIMAL to Dec, binary-charset columns to Bytes, DATE/TIME/DATETIME to strings, everything else to Str.
Example
conn ::mysql/connect({host: "localhost", user: "app", password: ::hot::ctx/get("mysql.password"), database: "shop"})
rows ::mysql/query(conn, "SELECT id, name FROM users WHERE active = ?", [true])
first(rows).name
::mysql/close(conn)
Types
MySqlOptions
MySqlOptions type {
host: Str?,
port: Int?,
user: Str,
password: Str?,
database: Str?,
ssl: Bool?,
tls: Map?
}
Connection options:
host(default "localhost"),port(default 3306)user(required),password(default "")database— initial schema (optional)ssl— upgrade to TLS before authenticating (default false)tls— options passed to::hot::tls/upgrade(e.g.ca-pem)