Skip to content

Commit

Permalink
Include more detail for implementing custom types for diesel::MultiCo…
Browse files Browse the repository at this point in the history
…nnection
  • Loading branch information
colem213 committed Jan 16, 2024
1 parent 166b97c commit 6329a7c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions diesel_derives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,8 +1630,29 @@ pub fn table_proc(input: TokenStream) -> TokenStream {
/// * `diesel::sql_types::Timestamp`
///
/// Support for additional types can be added by providing manual implementations of
/// `HasSqlType`, `FromSql` and `ToSql` for the corresponding type + the generated
/// database backend.
/// `HasSqlType`, `FromSql` and `ToSql` for the corresponding type, all databases included
/// in your enum, and the backend generated by this derive called MultiBackend.
/// For example to support `diesel::sql_types::TimestamptzSqlite` with the `time` crate:
/// ```
/// impl HasSqlType<TimestamptzSqlite> for MultiBackend {
/// fn metadata(lookup: &mut Self::MetadataLookup) -> Self::TypeMetadata {
/// MultiBackend::lookup_sql_type::<TimestamptzSqlite>(lookup)
/// }
/// }
///
/// impl FromSql<TimestamptzSqlite, MultiBackend> for OffsetDateTime {
/// fn from_sql(bytes: <MultiBackend as Backend>::RawValue<'_>) -> deserialize::Result<Self> {
/// bytes.from_sql::<OffsetDateTime, TimestamptzSqlite>()
/// }
/// }
///
/// impl ToSql<TimestamptzSqlite, MultiBackend> for OffsetDateTime {
/// fn to_sql<'b>(&'b self, out: &mut serialize::Output<'b, '_, MultiBackend>) -> serialize::Result {
/// out.set_value((TimestamptzSqlite, self));
/// Ok(IsNull::No)
/// }
/// }
/// ```
#[proc_macro_derive(MultiConnection)]
pub fn derive_multiconnection(input: TokenStream) -> TokenStream {
multiconnection::derive(syn::parse_macro_input!(input)).into()
Expand Down

0 comments on commit 6329a7c

Please sign in to comment.