moonbitstack/moonmysql/client does not have a README file

    MysqlConn

    pub struct MysqlConn {
    stream :
    Conn

    seq : Int
    closed : Bool
    server_kind :
    ServerKind

    streaming : Bool
    quote_mode :
    QuoteMode

    }

    A live MySQL connection over a raw TCP socket, speaking the wire protocol in pure MoonBit. This is the asynchronous, full-fidelity driver: it owns the socket for its whole lifetime, so begin/commit/rollback bracket a real server-side transaction. The synchronous @moondb.Driver adapter ([MysqlDriver]) is layered on top for the moondb contract.

    Framing is the classic 3-byte little-endian length + 1-byte sequence id header; the transport transparently reassembles the 0xFFFFFF continuation frames a large payload is split into.

    MysqlConn::begin

    async fn MysqlConn::begin(self : MysqlConn) -> Unit

    Begin a server-side transaction.

    MysqlConn::capabilities

    MysqlConn::close

    fn MysqlConn::close(self : MysqlConn) -> Unit

    Close the socket (best-effort, idempotent).

    MysqlConn::commit

    async fn MysqlConn::commit(self : MysqlConn) -> Unit

    Commit the current transaction.

    MysqlConn::connect

    async fn MysqlConn::connect(host : String, port : Int, user : String, password : String, database : String, tls? :
    Client
    , charset? : Int) -> MysqlConn

    Open a connection to host:port and complete the auth handshake against user/password, selecting database (empty for none). Works against both MySQL and MariaDB (the reported dialect is on [server_kind]).

    mysql_native_password and caching_sha2_password (MySQL 8's default, including the RSA full-auth path on a cache miss) are handled directly, whether the server drives them from its default or via an AuthSwitchRequest. With tls, the connection sends an SSLRequest after the greeting and runs the whole handshake over TLS; the caching_sha2 full-auth step then sends the password in cleartext under TLS instead of RSA-encrypting it. A switch to any other plugin (e.g. client_ed25519, on the README roadmap) raises [@moonmysql.MysqlError::UnsupportedError].

    MysqlConn::dialect

    MysqlConn::execute

    Run a non-row statement and report the rows affected and last insert id. With bound params it uses a prepared statement (binary protocol, out-of-band binding); without, the text protocol.

    MysqlConn::ping

    async fn MysqlConn::ping(self : MysqlConn) -> Bool

    MysqlConn::prepare

    MysqlConn::prepare_stmt

    async fn MysqlConn::prepare_stmt(self : MysqlConn, sql : String) -> MysqlStmt

    Ask the server to prepare sql and return the handle.

    MysqlConn::query

    async fn MysqlConn::query(self : MysqlConn, sql : String, params : Array[
    Value
    ]) -> Array[
    Row
    ]

    Run a row-returning statement and materialise every [@moondb.Row]. With bound params it uses a prepared statement (binary protocol); without, the text protocol.

    MysqlConn::query_multi

    async fn MysqlConn::query_multi(self : MysqlConn, sql : String, params : Array[
    Value
    ]) -> Array[Array[
    Row
    ]]

    Run a statement that answers with more than one result set and return every set, in the order the server sent them — a stored procedure's CALL, or a multi-statement packet. Values bind only on the prepared path, which has no multi-result protocol of its own, so params must be empty here.

    MysqlConn::query_stream

    async fn MysqlConn::query_stream(self : MysqlConn, sql : String, params : Array[
    Value
    ]) -> MysqlRowStream

    Send a row-returning statement and return a streaming cursor over its rows. The column definitions and their terminating EOF are consumed up front; the rows themselves are read one at a time by next.

    MysqlConn::rollback

    async fn MysqlConn::rollback(self : MysqlConn) -> Unit

    Roll back the current transaction.

    MysqlConn::server_kind

    The dialect (MySQL or MariaDB) reported by the server's handshake.

    MysqlDriver

    pub struct MysqlDriver {
    host : String
    port : Int
    user : String
    password : String
    database : String
    tls :
    Client
    ?
    }

    A synchronous @moondb.Driver over MySQL — the adapter that lets a moondb query layer (moonorm) talk to MySQL through the same contract as the SQLite and Postgres drivers.

    The async wall, and what it means here

    moonbitlang/async sockets are asynchronous, but @moondb.Driver's methods are synchronous, and MoonBit forbids calling an async function from a non-async one. The bridge is @async.run_async_main, which spins an event loop, runs an async body to completion, and returns — the same hook the toolchain uses to enter async fn main.

    A socket does not survive across two such event loops (each tears its file descriptors down; verified empirically), so every execute/query opens a fresh connection, authenticates, runs its one statement, and closes. That is correct and efficient enough for autocommit work — which is exactly what the moondb roundtrip is — but it means a transaction cannot be held open across separate Driver calls. begin/commit/rollback therefore raise a clear error directing callers to the asynchronous [MysqlConn] API, which owns its socket for its whole lifetime and brackets real transactions. This is a language constraint, not a shortcut, and it is documented in the README.

    MysqlDriver::begin

    MysqlDriver::capabilities

    MysqlDriver::close

    fn MysqlDriver::close(_self : MysqlDriver) -> Unit

    MysqlDriver::commit

    MysqlDriver::dialect

    MysqlDriver::new

    fn MysqlDriver::new(user~ : String, password? : String, database? : String, host? : String, port? : Int, tls? :
    Client
    ) -> MysqlDriver

    Configure a driver. host defaults to loopback, port to 3306; password and database may be empty. tls turns on TLS for the connection.

    MysqlDriver::ping

    fn MysqlDriver::ping(self : MysqlDriver) -> Bool

    MysqlDriver::prepare

    MysqlDriver::query_stream

    MysqlDriver::rollback

    fn MysqlDriver::rollback(_self : MysqlDriver) -> Unit raise
    DbError

    MysqlRowStream

    pub struct MysqlRowStream {
    conn : MysqlConn
    columns : Array[
    ColumnDef
    ]
    pending : Bytes?
    done : Bool
    }

    A forward-only cursor that reads a query's rows off the wire on demand instead of buffering them — the streaming counterpart to [query], for results too large to materialise at once (mysql_use_result, SQLAlchemy's stream_results). Bound to its MysqlConn, a single-command pipeline: the stream must be drained (next returns None) or closed before another statement runs on that connection.

    MysqlRowStream::close

    async fn MysqlRowStream::close(self : MysqlRowStream) -> Unit

    Abandon the stream early, draining any unread rows to the terminating EOF so the connection can run the next statement. Idempotent once the stream is done.

    MysqlRowStream::next

    The next row, or None at the EOF that ends the result set. An ErrorResponse mid-stream is raised.

    MysqlStmt

    pub struct MysqlStmt {
    conn : MysqlConn
    id : Int
    text : String
    slots : Array[String]
    params : Array[
    Value
    ]
    closed : Bool
    }

    A statement MySQL prepares once and runs many times.

    prepare sends COM_STMT_PREPARE and keeps the server-side handle; every execute/query sends only the statement id and the values, which is both cheaper than re-parsing and the path that binds binary payloads without hex expansion. close sends COM_STMT_CLOSE, after which the handle raises Closed.

    A :name statement is rewritten to MySQL's ? spelling at prepare time and the slot names are kept, so bind_named works without the caller counting anything. A handle belongs to the connection that prepared it: one wire, one statement at a time.