Skip to content

Suggestion: custom struct attributes #67

@LukasLohmar

Description

@LukasLohmar

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>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions