Insert

Derive Macro Insert 

Source
#[derive(Insert)]
{
    // Attributes available to this derive:
    #[insert]
}
Expand description

Derives an implementation for Insert on a struct with named fields, allowing that struct to be used to be used to create an entry in the store.

Configuration for #[insert(...)] container attr

  • iden_enum Required. The enum of Iden variants for the corresponding model.

Configuration for #[insert(...)] field attr

  • iden Optional. Override the computed Iden variant for this field.

ยงExamples

use bodega::{Select, Insert, uuid_id};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[uuid_id]
pub struct BookId(Uuid);

#[derive(Debug, Clone, PartialEq, Eq, sqlx::FromRow, Select)]
#[sea_query::enum_def]
pub struct Book {
    id: BookId,
    title: String,
    author: String,
    pages: i64,
    created_at: DateTime<Utc>,
    updated_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Insert)]
#[insert(iden_enum = BookIden)]
pub struct BookCreate {
    title: String,
    // unnecessary override for example
    #[insert(iden = BookIden::Author)]
    author: String,
    pages: i64,
}