Trait diesel::sql_types::HasSqlType[][src]

pub trait HasSqlType<ST>: TypeMetadata {
    fn metadata(lookup: &Self::MetadataLookup) -> Self::TypeMetadata;
}
Expand description

Indicates that a SQL type exists for a backend.

Deriving

This trait can be automatically derived by #[derive(SqlType)]. This derive will also implement NotNull and SingleValue. When deriving this trait, you need to specify how the type is represented on various backends. You don’t need to specify every backend, only the ones supported by your type.

For PostgreSQL, add #[postgres(oid = "some_oid", array_oid = "some_oid")] or #[postgres(type_name = "pg_type_name")] if the OID is not stable. For MySQL, specify which variant of MysqlType should be used by adding #[mysql_type = "Variant"]. For SQLite, specify which variant of SqliteType should be used by adding #[sqlite_type = "Variant"].

Example

#[derive(SqlType)]
#[postgres(oid = "23", array_oid = "1007")]
#[sqlite_type = "Integer"]
#[mysql_type = "Long"]
pub struct Integer;

Required methods

Fetch the metadata for the given type

This method may use lookup to do dynamic runtime lookup. Implementors of this method should not do dynamic lookup unless absolutely necessary

Implementors