Expand description
Database driver traits and capability descriptions. Database driver interface for Toasty.
This module defines the traits and types that database drivers must implement
to integrate with the Toasty query engine. The two core traits are [Driver]
(factory for connections and schema operations) and Connection (executes
operations against a live database session).
The query planner inspects [Capability] to decide which [Operation]
variants to emit. SQL-based drivers receive [Operation::QuerySql] and
[Operation::Insert], while key-value drivers (e.g., DynamoDB) receive
[Operation::GetByKey], [Operation::QueryPk], etc. The
[SchemaMutations] sub-struct (Capability::schema_mutations) describes
what the database can do to its own schema — for example, whether
ALTER COLUMN can change a column’s type — and the migration generator
consults it to decide between an in-place alter and a table rebuild.
§Architecture
Query Engine ──▶ Operation ──▶ Connection::exec() ──▶ ExecResponse
▲
│
Driver::capability()§Error classification
The pool and the engine branch on the error variant returned from
Connection::exec and Connection::ping. Drivers MUST cooperate
with those branches:
-
A connection-level fault (closed socket, broken pipe, protocol error, end-of-stream during handshake) MUST be classified as
crate::Error::connection_lost. The pool uses that signal to evict the slot and to wake the background sweep, which then pings the remaining idle connections and drops any that also fail. Any other error variant for the same condition leaks a dead connection back into the pool. -
A retryable transaction conflict (PostgreSQL SQLSTATE
40001, MySQL error1213) SHOULD be classified ascrate::Error::serialization_failure. The engine does not retry automatically; the classification is propagated to user code so the caller can decide. -
A write attempted against a read-only session (PostgreSQL
25006, MySQL1792) SHOULD be classified ascrate::Error::read_only_transaction.
Other backend errors are typically wrapped with
crate::Error::driver_operation_failed.
Re-exports§
pub use operation::IsolationLevel;pub use operation::Operation;
Modules§
- operation
- Database operations dispatched to drivers.
Structs§
- Capability
- Describes what a database driver supports.
- Exec
Response - The result of a database operation.
- Schema
Mutations - The database’s capabilities to mutate the schema (tables, columns, indices).
- Storage
Types - Maps application-level types to the concrete database column types used for storage.
Enums§
- Rows
- The payload of an
ExecResponse.
Traits§
- Connection
- A live database session that can execute
Operations. - Driver
- Factory for database connections and provider of driver-level metadata.