rustio-admin-cli 0.2.0

Command-line tools for rustio-admin: project scaffolding, migrations, user management.
//! Generated by `rustio startapp {{name}}`. Customise freely.

use chrono::{DateTime, Utc};
use rustio_admin::{Error, Model, ModelAdmin, Row, RustioAdmin, Value};

#[derive(RustioAdmin)]
pub struct {{Singular}} {
    pub id: i64,
    pub name: String,
    pub created_at: DateTime<Utc>,
}

impl Model for {{Singular}} {
    const TABLE: &'static str = "{{table}}";
    const COLUMNS: &'static [&'static str] = &["id", "name", "created_at"];
    const INSERT_COLUMNS: &'static [&'static str] = &["name", "created_at"];

    fn id(&self) -> i64 {
        self.id
    }

    fn from_row(row: Row<'_>) -> Result<Self, Error> {
        Ok(Self {
            id: row.get_i64("id")?,
            name: row.get_string("name")?,
            created_at: row.get_datetime("created_at")?,
        })
    }

    fn insert_values(&self) -> Vec<Value> {
        vec![self.name.clone().into(), self.created_at.into()]
    }
}

// Empty `impl ModelAdmin` opts the model into `Admin::model::<…>()`
// with every framework default. Override hooks (list_display,
// list_filter, search_fields, ordering, …) to customise the list
// page — see https://github.com/abdulwahed-sweden/rustio-admin/blob/main/docs/modeladmin.md
impl ModelAdmin for {{Singular}} {}