pub struct Capability {Show 22 fields
pub sql: bool,
pub storage_types: StorageTypes,
pub schema_mutations: SchemaMutations,
pub cte_with_update: bool,
pub select_for_update: bool,
pub returning_from_mutation: bool,
pub primary_key_ne_predicate: bool,
pub auto_increment: bool,
pub native_varchar: bool,
pub native_timestamp: bool,
pub native_date: bool,
pub native_time: bool,
pub native_datetime: bool,
pub native_enum: bool,
pub named_enum_types: bool,
pub native_decimal: bool,
pub bigdecimal_implemented: bool,
pub decimal_arbitrary_precision: bool,
pub index_or_predicate: bool,
pub native_starts_with: bool,
pub native_like: bool,
pub test_connection_pool: bool,
}Expand description
Describes what a database driver supports.
The query planner reads these flags to decide which Operation
variants to generate. For example, a SQL driver sets sql: true and
receives QuerySql operations, while DynamoDB sets sql: false and
receives key-value operations like GetByKey and QueryPk.
Pre-built configurations are available as associated constants:
SQLITE, POSTGRESQL,
MYSQL, and DYNAMODB.
§Examples
use toasty_core::driver::Capability;
let cap = &Capability::SQLITE;
assert!(cap.sql);
assert!(cap.returning_from_mutation);
assert!(!cap.select_for_update);Fields§
§sql: boolWhen true, the database uses a SQL-based query language and the
planner will emit QuerySql operations.
storage_types: StorageTypesColumn storage types supported by the database.
schema_mutations: SchemaMutationsSchema mutation capabilities supported by the datbase.
cte_with_update: boolSQL: supports update statements in CTE queries.
select_for_update: boolSQL: Supports row-level locking. If false, then the driver is expected to serializable transaction-level isolation.
returning_from_mutation: boolSQL: Mysql doesn’t support returning clauses from insert / update queries
primary_key_ne_predicate: boolDynamoDB does not support != predicates on the primary key.
auto_increment: boolWhether the database has an auto increment modifier for integer columns.
native_varchar: boolWhether the database supports VARCHAR(n) column types natively.
Must be consistent with StorageTypes::varchar: when true,
varchar must be Some; when false, varchar must be None.
Use Capability::validate to check this invariant.
native_timestamp: boolWhether the database has native support for Timestamp types.
native_date: boolWhether the database has native support for Date types.
native_time: boolWhether the database has native support for Time types.
native_datetime: boolWhether the database has native support for DateTime types.
native_enum: boolWhether the database supports native enum types.
- PostgreSQL:
true—CREATE TYPE ... AS ENUM - MySQL:
true— inlineENUM('a', 'b')column type - SQLite:
false— usesTEXT+CHECKconstraint - DynamoDB:
false— plain string attribute
named_enum_types: boolWhether enum types are standalone named objects requiring separate DDL.
When true, migrations must emit CREATE TYPE / ALTER TYPE for enum
types. When false, enum definitions are inline in column types.
- PostgreSQL:
true—CREATE TYPE <name> AS ENUM (...) - MySQL:
false— inlineENUM('a', 'b')on the column - SQLite:
false - DynamoDB:
false
native_decimal: boolWhether the database has native support for Decimal types.
bigdecimal_implemented: boolWhether BigDecimal driver support is implemented. TODO: Remove this flag when PostgreSQL BigDecimal support is implemented. Currently only MySQL has implemented BigDecimal driver support.
decimal_arbitrary_precision: boolWhether the database’s decimal type supports arbitrary precision. When false, the decimal type requires fixed precision and scale to be specified upfront.
- PostgreSQL: true (NUMERIC supports arbitrary precision)
- MySQL: false (DECIMAL requires fixed precision/scale)
- SQLite/DynamoDB: false (no native decimal support, stored as TEXT)
index_or_predicate: boolWhether OR is supported in index key conditions (e.g. DynamoDB KeyConditionExpression). DynamoDB: false. All other backends: true (SQL backends never use index key conditions).
native_starts_with: boolWhether the database has a native prefix-match operator that does not
require LIKE-style escaping. When true, starts_with is left in the
AST and the driver renders it natively (DynamoDB’s begins_with(),
PostgreSQL’s ^@). When false, the lowering rewrites it to a
LIKE expression — which requires native_like to be true.
native_like: boolWhether the database has a native LIKE expression. When false,
Expr::Like cannot be sent to the driver; starts_with lowering
will not produce one.
test_connection_pool: boolWhether to test connection pool behavior.
TODO: We only need this for the connection_per_clone.rs test, come up with a better way.
Implementations§
Source§impl Capability
impl Capability
Sourcepub const POSTGRESQL: Self
pub const POSTGRESQL: Self
PostgreSQL capabilities
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates the consistency of the capability configuration.
This performs sanity checks to ensure the capability fields are
internally consistent. For example, if native_varchar is true,
then storage_types.varchar must be Some, and vice versa.
Returns an error if any inconsistencies are found.
Sourcepub fn default_string_max_length(&self) -> Option<u64>
pub fn default_string_max_length(&self) -> Option<u64>
Returns the default string length limit for this database.
This is useful for tests and applications that need to respect database-specific string length constraints.
Sourcepub fn native_type_for(&self, ty: &Type) -> Type
pub fn native_type_for(&self, ty: &Type) -> Type
Returns the native database type for an application-level type.
If the database supports the type natively, returns the same type. Otherwise, returns the bridge/storage type that the application type maps to in this database.
This uses the existing db::Type::bridge_type() method to determine
the appropriate bridge type based on the database’s storage capabilities.