MySQL and MariaDB — 0.18.0 Developer Preview

SDK 0.18.0 adds native mysql_find and mysql_execute with bound positional values and strict result records. Actual generated programs have run against separate disposable verified-TLS MySQL 8.4.8 and MariaDB 11.8.9 fixtures. The exact SDK archive passed49 installed tests and six generated-language tests against each engine independently: MySQL8.4.8 and MariaDB11.8.9, with no failures or skips. Source-generated development tests and artifact tests remain separately identified in the versioned report. See [the checkpoint](NEXT-RUN.md) and the versioned release report for the final status.

This milestone supports single-record CRUD. It does not provide a MySQL connection pool, transaction callback/handle, migrations or multi-row result list. PostgreSQL's pool and transaction APIs do not apply to MySQL calls. Developer Preview does not imply production readiness or support for untested server versions and platforms.

Native language API

CallResultMeaning
mysql_find(sql, RecordType)RecordType?!Query without parameters: zero rows → none, one row → some(record), more than one → error
mysql_find(sql, parameters, RecordType)RecordType?!Same query with bound parameter-record fields
mysql_execute(sql)Int!Execute a statement without parameters and return affected rows
mysql_execute(sql, parameters)Int!Execute with bound parameter-record fields and return affected rows

sql is a String. RecordType names a declared flat record whose fields are Int, Bool, String, or their Optional forms. The parameter record uses the same supported scalar types. Calls suspend cooperatively without await. Browser Check accepts supported syntax; browser Run rejects database execution. No browser connection or simulated success is provided.

Parameters bind to ? placeholders in **record declaration order**, regardless of the order of named constructor arguments. The language API does not expose named :parameter binding. Placeholders represent values, not table/column identifiers or SQL keywords. Choose SQL structure in application code and bind untrusted values separately.

type UserKey:
  id: Int

type User:
  id: Int
  active: Bool
  name: String
  bio: String?

fn user_name(id: Int) -> String:
  found = mysql_find("SELECT id, active, name, bio FROM threadone_users WHERE id = ?", UserKey(id: id), User) or return "Database unavailable"
  user = found or return "User not found"
  return user.name

fn main():
  print(user_name(42))

This example requires a configured database and matching table. The first or handles query failure; the second handles a successful missing row. A NULL Optional field inside a present record is different from the outer none indicating no row. Empty text is present, not missing.

Result codecs and parameter coercion

ThreadOne resultAccepted database metadata/valueRejection boundary
Int / Int?Integer wire types, including unsigned values that fit signed 64-bitUnsigned values above Int maximum are errors; no decimal/float narrowing
Bool / Bool?TINYINT(1) metadata, with each non-NULL value exactly 0 or 1Other widths or values such as 2 are errors; MySQL has no separate BOOL wire type
String / String?Nonbinary text metadata and valid UTF-8 bytes after SET NAMES utf8mb4Binary character set, binary data, invalid UTF-8, ENUM/SET and unsupported types are errors
Optional result noneSQL NULL in a field declared OptionalNULL in a required field is an error

Result column count, order, names and supported metadata must match the declared record, even when a query returns no rows. Select explicit columns and alias them to the record field names. Nested records, lists, native JSON, decimal, floating point, temporal and BIT results are unsupported. MariaDB's JSON alias is LONGTEXT and is handled as ordinary text; this is not typed JSON validation or evidence of MySQL native JSON support.

**Bound parameter types do not validate the target SQL column types.** MySQL/MariaDB may coerce signed integers, Boolean values encoded as 0/1, and text according to the server schema, version and SQL mode. The client encodes every Optional none as protocol NULL; its declared scalar kind does not survive that encoding. Consequently Int? none can be accepted by a nullable text target. This differs from the PostgreSQL parameter-kind contract. Strict result decoding does not guarantee strict storage conversion: use suitable database schema, constraints and SQL modes, then validate the application rules you need.

mysql_execute returns the server/driver's affected-row count and rejects statements that return columns. Do not interpret it as a count of all rows matching an UPDATE predicate: server/client affected-row semantics can distinguish unchanged and changed rows. For a supported statement returning one record, use mysql_find with the matching schema. A write may have applied before a returned row fails decoding or exceeds a bound; the error is not a rollback guarantee.

SQL scope

Each call prepares one statement. Supported leading statement keywords are SELECT, INSERT, UPDATE, DELETE, WITH, CREATE, ALTER, DROP and TRUNCATE. Multi-statement batches, CALL, dynamic PREPARE/EXECUTE, explicit transaction control and unsupported statement forms are rejected. Executable-comment markers /*! and /*M! are rejected conservatively, including when those markers occur inside quoted SQL text; pass such text as a bound value instead.

The adapter rejects extra result sets rather than flattening them into a language record. This statement boundary is not a SQL security sandbox. Use trusted application SQL; SQL functions, triggers, server configuration and privileges still determine effects. DDL is available for the disposable example setup, not an automatic migration facility.

TLS and connection lifecycle

Set THREADONE_MYSQL_URL outside source code using a mysql:// URL with the intended host and database. This same variable is used for either MySQL or MariaDB; select the desired server explicitly. Optional THREADONE_MYSQL_CA_PEM contains private CA certificate PEM text. TLS verifies the certificate chain and hostname. Plaintext, invalid-certificate acceptance, hostname-verification bypass and Unix-socket fallback are not supported.

Each call owns a separate session. Temporary tables, session settings and transaction state do not persist across calls. Calling postgres_transaction does not enlist MySQL statements in a PostgreSQL transaction. There is no automatic statement retry, and database errors deliberately omit supplied credentials and query values.

After a successful operation, consuming connection close has a separate one-second budget while the binding admission slot remains held. A known-successful affected-row count or decoded result is preserved if cleanup fails. Failure/cancellation discards the established connection; its cleanup can retain shared driver admission capacity for up to one additional second. The upstream handshake-cancellation exception is described below. A local timeout or disconnect does not prove immediate server query cancellation. A potentially applied write may have an unknown outcome, so reconcile application data before retrying. A successful statement must not be retried merely because later connection cleanup failed.

Limits and memory ownership

ResourceLimit and scope
Active binding calls8 shared process slots
Pending binding callsUp to 32 admission waiters
Admission wait5 seconds
Connect plus statement5 seconds after binding admission
Established-session cleanupUp to 1 additional second; upstream handshake-cancellation exception below
URL / CA PEM16 KiB / 64 KiB
SQL textNonempty; at most 64 KiB UTF-8
Bound parametersAt most 64; String payload at most 1 MiB in aggregate
Result schema1–64 unique fields; names 1–256 UTF-8 bytes
Find resultAt most one row and 1 MiB decoded scalar payload
Driver packet setting16 MiB; not a total process-memory bound

The result budget counts UTF-8 String bytes, eight bytes per Int and one byte per Bool or NULL. Checks occur after the driver has received/decoded the result and before copying accepted text into the application/request arena. Arena capacity is checked for the complete row before copying it. Driver buffers, metadata, TLS state and allocation overhead are additional. The eight-slot bound covers active binding calls, not all background cleanup tasks or server-side sessions. In particular, cancellation during the upstream mysql_async connection handshake may start cleanup that the adapter cannot directly track; a stronger bound on that path requires upstream review or a vendor change. Sessions still closing and server work after disconnect may also outlive the caller. Do not interpret this as an eight-connection server cap.

Timers are cooperative: they cannot preempt non-yielding CPU work. HTTP handler deadlines may expire earlier. Generated records retain their arena lifetime across cooperative suspension; no user-visible session handle escapes the call.

Example and evidence

Use [the CRUD example](../sdk/examples/mysql.one) with [its setup notes](../sdk/examples/mysql-README.md) only against an explicitly selected disposable database. It creates a test table, binds SQL-looking text as data, checks NULL/present values, updates, deletes and verifies absence.

Source-generated programs have separate live evidence for MySQL 8.4.8 and MariaDB 11.8.9. A MySQL pass must not be relabelled MariaDB compatibility, or vice versa. Release validation records153 compiler tests,193 integrity-checked vendored crates,49 exact-ZIP installed tests with no skips, 12 adapter tests against each server independently, and six exact-artifact generated-language tests per engine, with no failures or skips in those final suites. Consult the versioned report for the final artifact hash and separate generated-language/server evidence. These checks do not establish clean-OS setup, Windows/macOS/ARM64 execution, replication/failover, MySQL transactions/pooling or production readiness.

สรุปการใช้งานภาษาไทย

SDK 0.18.0 เพิ่ม mysql_find และ mysql_execute สำหรับ native SDK ใช้กับ MySQL หรือ MariaDB ผ่าน THREADONE_MYSQL_URL และ TLS ที่ตรวจใบรับรอง/ชื่อโฮสต์ หากใช้ CA ภายในให้ใส่เนื้อหา PEM ใน THREADONE_MYSQL_CA_PEM ผลทดสอบ MySQL 8.4.8 และ MariaDB 11.8.9 มาจาก fixture แยกกัน ZIPจริงผ่าน49 installed tests และgenerated-language testsจากartifactเดียวกัน6เคสต่อserver ไม่มีfailedหรือskip ดูรายงานรุ่นสำหรับhashและหลักฐานแยกแต่ละชุด ไม่ใช้ผลของserverหนึ่งแทนอีกserverหนึ่ง

ส่งค่าด้วย ? ตามลำดับ field ที่ประกาศในชนิด record ไม่ต่อค่าจากผู้ใช้ลง SQL โดยตรง mysql_find คืน Record?!: จัดการ error ก่อน แล้วจึงแยกไม่พบแถวออกจาก record ที่มีข้อมูล; มากกว่าหนึ่งแถวเป็น error ชื่อ ลำดับและชนิดคอลัมน์ต้องตรงแม้ผลไม่มีแถว รองรับ Int, Bool, String และ Optional; Bool ต้องเป็น metadata TINYINT(1) และค่าต้องเป็น0หรือ1 ข้อความว่างไม่ใช่ NULL

การ bind ป้องกันค่าถูกตีความเป็น SQL แต่ **ไม่รับรองว่าคอลัมน์ปลายทางมีชนิดตรงกับ record** เพราะ server อาจแปลงค่าตาม schema/SQL mode และ none ทุกชนิดถูกส่งเป็น NULL ที่ไม่เก็บชนิดเดิม เช่น Int? none อาจบันทึกลงคอลัมน์ข้อความที่รับ NULL ได้ ต้องกำหนด constraints และตรวจ business rules เพิ่มเอง

แต่ละ call เปิด session แยก ยังไม่มี MySQL pool หรือ transaction API ในภาษา ไม่เก็บ temporary table หรือ transaction ข้าม calls และไม่เข้าร่วม postgres_transaction คำสั่งเขียนไม่ retry อัตโนมัติ หาก timeout/ขาดการเชื่อมต่อ ผลเขียนอาจไม่ทราบ ต้องตรวจข้อมูลก่อนลองใหม่ การปิด connection ไม่ยืนยันว่า server หยุดงานทันที และการcancelระหว่างhandshakeอาจเริ่มcleanupภายในupstreamที่adapterติดตามโดยตรงไม่ได้ จึงไม่รับรองว่าbackground tasksหรือserver sessionsทั้งหมดมีไม่เกิน8

ขอบเขตหลักคือ8 callsพร้อมกัน/32รอ, รอ admissionไม่เกิน5วินาทีแล้ว connect+statementไม่เกิน5วินาที, cleanupไม่เกินอีก1วินาที, SQL64KiB, พารามิเตอร์ข้อความรวม1MiB และผลแถวเดียว1MiBหลังถอดรหัส ไม่ใช่ขอบเขตหน่วยความจำทั้ง process หรือการรับรองจำนวน sessionที่serverยังปิดไม่เสร็จ รุ่นนี้ยังเป็น Developer Preview