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

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

    fn row_metadata(
        out: &mut Vec<Self::TypeMetadata>,
        lookup: &Self::MetadataLookup
    ) { ... } }

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

Provided Methods

Fetch the metadata for a tuple representing an entire row

The default implementation of this method simply calls Self::metadata. You generally should not need to override this method.

However, if you are writing an implementation of HasSqlType that simply delegates to an inner type (for example, Nullable does this), then you should ensure that you delegate this method as well.

Implementors