User model and CRUD calls. The pool or transaction type selects the driver:
Each enabled driver gets a validated SQLx
FromRow implementation. The adapter uses native parameter binding, identifier quoting and pagination syntax. PostgreSQL and SQLite return written rows with RETURNING. MySQL reads the stored row by its key on the same transaction and connection, then validates it before committing; unchanged updates still return the existing row. Omitted keys use the returned insert ID. Explicit zero keys follow MySQL’s SQL mode, and the returned model contains the stored key.
Use User::create_table_sql::<rydantic::sqlx::Postgres>() and User::create_index_sql::<rydantic::sqlx::Postgres>() to preview DDL. Select Sqlite or MySql as the type parameter for another driver. Schema creation and CRUD reject overlong server identifiers before executing SQL. Generated server index and foreign-key names fit identifier limits.
MySQL creates InnoDB tables with utf8mb4_0900_bin collation and inline indexes/foreign keys. Unbounded text/binary fields use LONGTEXT/LONGBLOB. Keys, unique/indexed fields and references use VARCHAR/VARBINARY: #[sql(length = N)] overrides the model’s max_length, with a default of 191 when neither is set. Writes check those bounds before executing SQL and report sql_length with a field path. Select bounds that fit the server’s row/index limits, and use compatible definitions for referenced columns.
MySQL create_table requires a pool and rejects borrowed connections or transactions with sql_ddl_connection, preserving caller-owned transactions from DDL’s implicit commits. Its indexes are included when creating a new table, so create_index_sql::<MySql>() returns an empty list. Use migrate to upgrade existing tables from model definitions. PostgreSQL and SQLite schema creation can participate in caller-owned transactions.
Configure production connection options with SQLx’s PgConnectOptions or MySqlConnectOptions, including the desired TLS verification policy.