diesel_cli_ext icon indicating copy to clipboard operation
diesel_cli_ext copied to clipboard

Add support for generating code with owned values

Open banool opened this issue 3 months ago • 0 comments

Right now strings and perhaps other types are generated using &'a str:

#[derive(Insertable)]
#[diesel(table_name = blob)]
pub struct NewBlob<'a> {
    pub blob_name: &'a str,
    pub placement_group: &'a str,
    pub size_bytes: BigDecimal,
    pub slice_address: &'a str,
    pub num_chunksets: BigDecimal,
    pub blob_commitment: &'a str,
    pub owner_address: &'a str,
    pub is_written: bool,
    pub is_deleted: bool,
    pub created_ts: DateTime<Utc>,
    pub expires_ts: DateTime<Utc>,
    pub updated_ts: DateTime<Utc>,
    pub updated_txn_version: BigDecimal,
}

For things like batch inserting it can help to create owned versions of these structs, like this:

#[derive(Insertable)]
#[diesel(table_name = blob)]
pub struct NewBlob<'a> {
    pub blob_name: String,
    pub placement_group: String,
    pub size_bytes: BigDecimal,
    pub slice_address: String,
    pub num_chunksets: BigDecimal,
    pub blob_commitment: String,
    pub owner_address: String,
    pub is_written: bool,
    pub is_deleted: bool,
    pub created_ts: DateTime<Utc>,
    pub expires_ts: DateTime<Utc>,
    pub updated_ts: DateTime<Utc>,
    pub updated_txn_version: BigDecimal,
}

banool avatar Nov 03 '25 14:11 banool