mysql

A MySQL/MariaDB client written in Ecko: classic protocol + mysql_native_password over std.net.

ecko get github.com/ecko-lang/mysql-client
import mysql

ecko get records this under mysql_client. This page imports it as mysql - fetch it with ecko get github.com/ecko-lang/mysql-client --as mysql to record that name instead, or rename the key in your ecko.json.

Declares net. A capability is only advisory in the manifest: what the package actually gets is the grant you give it when you import it.

Version 0.39.0 - source - MIT.


connect(cfg)

connect({ host, port, user, password, database }) -> a connection handle.

connect_tls(cfg)

Connect to MySQL over TLS and complete authentication. Same cfg as connect. Needs the net capability.

close(sock)

Close the connection.

query(sock, sql, params = [])

query(sock, sql, params = []) -> a list of row maps (empty for non-SELECT statements). Each ? in sql takes the next value of params, written as a SQL literal that nothing in the value can break out of - pass user input here rather than building it into the SQL string. A sql { } block works in place of the string and the list.

transaction(sock, body)

transaction(db, fn) runs fn(db) inside a transaction: it commits when fn returns, and rolls back and re-raises if fn raises. A commit that fails is rolled back too, and raises. Returns what fn returned. Transactions do not nest: starting one inside another raises.