#enums #postgresql #diesel #proc-macro

macro diesel-enum-sqltype

Provides derive macro for FromSql and ToSql traits for postgres enums

7 releases

0.1.7 Feb 18, 2025
0.1.6 Nov 28, 2024
0.1.5 Sep 6, 2024

#337 in Procedural macros

Download history 1/week @ 2024-11-13 109/week @ 2024-11-27 9/week @ 2024-12-04 3/week @ 2024-12-11 1/week @ 2024-12-18 17/week @ 2024-12-25 63/week @ 2025-02-12 65/week @ 2025-02-19 6/week @ 2025-02-26

134 downloads per month

MIT license

7KB
93 lines

Diesel Enum Derive Macro

Overview

A Rust procedural macro library that provides custom derive macros FromSqlDerive and ToSqlDerive for seamless PostgreSQL enum serialization and deserialization with Diesel ORM.

Features

  • Automatically implement FromSql and ToSql traits for PostgreSQL enum types
  • Simple attribute-based configuration
  • Works with unit variants of enums
  • Supports custom SQL type specification

Installation

Add to your Cargo.toml:

[dependencies]
diesel-enum-sqltype = "0.1.6"
diesel = { version = "x.x.x", features = ["postgres"] }

Usage

#[derive(FromSqlDerive, ToSqlDerive)]
#[diesel(sql_type = "PaymentTypeT")] //imported from schema.rs
enum PaymentType {
    Card,
    Bank,
    Wire,
}

Limitations

  • Only supports enums with unit variants
  • Requires explicit sql_type attribute

License

MIT

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Dependencies

~190–620KB
~15K SLoC