diesel_cli_ext icon indicating copy to clipboard operation
diesel_cli_ext copied to clipboard

Suggestion: custom struct attributes

Open LukasLohmar opened this issue 5 months ago • 1 comments

i ran into an issue with sqlite. the generated struct needs #[diesel(check_for_backend(diesel::sqlite::Sqlite))] attribute to compile and it seems there is no way to set it right now

i figured it would be pretty awesome to have the possibility to add any attribute we want to our generated structs

inside my fork its already implemented and works like the following:

diesel_ext.exe --import-types "crate::schema::*" --derive "AsChangeset, Insertable, Queryable, Selectable, Debug" --struct-attribute "#[diesel(check_for_backend(diesel::sqlite::Sqlite))]" --add-table-name --model > src/database/src/models.rs

#[derive(AsChangeset, Insertable, Queryable, Selectable, Debug)]
#[diesel(table_name = user_tokens)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct UserToken {
    pub id: Option<i32>,
    pub user_id: Vec<u8>,
    pub token: Vec<u8>,
    pub lifetime: Option<NaiveDateTime>,
}

LukasLohmar avatar Sep 04 '24 13:09 LukasLohmar