@@ -37,7 +37,8 @@ Can currently:
3737- [x] Insert (ignoring auto fields)
3838- [x] Update
3939- [x] Delete
40- - [x] Support for enums
40+ - [x] Support for enums with ` #[custom_enum] ` attribute for proper PostgreSQL enum handling
41+ - [x] Support for optional enums
4142- [x] Create a version of https://github.com/jayy-lmao/sql-gen for generating these
4243
4344### Roadmap
5556### Examples
5657
5758``` rs
59+ // First, define your custom enum if needed
60+ #[derive(sqlx:: Type , Debug , Clone )]
61+ #[sqlx(type_name = " user_status" , rename_all = " snake_case" )]
62+ pub enum UserStatus {
63+ Verified ,
64+ Unverified ,
65+ }
66+
5867#[derive(DbSet , Debug )] // DbSet also implements sqlx::FromRow by default
5968#[dbset(table_name = " users" )] // Used for queries, will be used for codegen
6069pub struct User {
@@ -64,6 +73,8 @@ pub struct User {
6473 details : Option <String >, // wont be required for insert
6574 #[unique]
6675 email : String , // Will generate `::one` queries as it's unique
76+ #[custom_enum] // Marks this field as a PostgreSQL enum for proper SQL handling
77+ status : UserStatus , // Will be correctly cast in SQL queries
6778}
6879
6980// Fetch one user
@@ -109,6 +120,7 @@ let inserted_user = UserDbSet::insert()
109120 . id (" id-3" . to_string ())
110121 . email (" steven@stevenson.com" . to_string ())
111122 . name (" steven" . to_string ())
123+ . status (UserStatus :: Verified )
112124 . insert (pool ) // Due to type-state insert can't be called until all non-nullable (besides auto) fields have been set
113125 . await ? ;
114126
0 commit comments