Skip to main content

Columns

Derive Macro Columns 

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

A part of a row, flattened into it with #[sqlx(flatten)]: its columns are the row’s. Its fields take the same flags as a row’s; on the struct, only #[row(crate = "…")].

use chrono::{DateTime, Utc};

/// When a row was created, for every table that keeps it.
#[derive(sqlx::FromRow, Clone, magic_sync::Columns)]
pub struct Stamps {
    #[row(created)]
    pub created_at: DateTime<Utc>,
}

#[derive(sqlx::FromRow, Clone, magic_sync::Row)]
#[row(table = "notes", mirror = "record")]
pub struct Note {
    pub id: uuid::Uuid,
    pub text: String,
    #[sqlx(flatten)]
    pub stamps: Stamps,
}

Implements magic_sync::Columns for a part of a row, which the row brings in with #[sqlx(flatten)]. Use it as magic_sync::Columns: its fields take the same #[row(…)] flags as a row’s, and the struct only crate.