Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to add derive annotations when generating Diesel models via diesel_cli_ext?

I am using diesel_cli_ext to generate Rust model code:

diesel_ext --schema-file src/model/diesel/dolphin/dolphin_schema.rs --model > src/model/diesel/dolphin/dolphin_models.rs

The generated model looks like this:

#[derive(Queryable, Debug)]
pub struct AdminUser {
    pub id: i64,
    pub nickname: Option<String>,
    pub avatar_url: Option<String>,
    pub phone: Option<String>,
    pub updated_time: Option<i64>,
    pub created_time: Option<i64>,
    pub salt: Option<String>,
    pub pwd: Option<String>,
    pub sex: Option<i32>,
    pub level_type: Option<String>,
    pub phone_region: Option<String>,
    pub country_code: Option<i32>,
    pub user_status: Option<String>,
}

Is it possible to add more annotations when generating the model? I’d like to have these derives:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#[derive(Serialize, Queryable, Deserialize, Default)]

I have been adding it by myself, but the next generation overwrites the previous modifications.

>Solution :

Reading the "how to use" documentation shows that a command line option allows you to modify the derives:

    -d, --derive DERIVES
                        set struct derives

There’s also an issue for per-table derive modifications.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading