use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, sqlx::FromRow)]
pub struct Post {
pub id: i64,
pub title: String,
pub body: String,
pub published_at: Option<DateTime<Utc>>,
}
impl Post {
pub fn objects() -> crate::orm::Manager<Post> {
crate::orm::Manager::new()
}
}
impl crate::orm::Model for Post {
type PrimaryKey = i64;
const NAME: &'static str = "Post";
const TABLE: &'static str = "post";
const FIELDS: &'static [crate::orm::FieldSpec] = &[
crate::orm::FieldSpec {
name: "id",
ty: crate::orm::SqlType::BigInt,
primary_key: true,
nullable: false,
supported_backends: &[],
fk_target: None,
noform: false,
privileged: false,
private: false,
secret: false,
db_constraint: true,
noedit: false,
auto_user_add: false,
auto_user: false,
is_string_repr: false,
max_length: 0,
choices: &[],
choice_labels: &[],
default: "",
is_multichoice: false,
unique: false,
on_delete: crate::orm::FkAction::NoAction,
on_update: crate::orm::FkAction::NoAction,
index: false,
auto_now_add: false,
auto_uuid: false,
auto_now: false,
trim: false,
lowercase: false,
case_insensitive: false,
help: "",
example: "",
widget: None,
min: None,
max: None,
text_format: ::core::option::Option::None,
slug_from: ::core::option::Option::None,
},
crate::orm::FieldSpec {
name: "title",
ty: crate::orm::SqlType::Text,
primary_key: false,
nullable: false,
supported_backends: &[],
fk_target: None,
noform: false,
privileged: false,
private: false,
secret: false,
db_constraint: true,
noedit: false,
auto_user_add: false,
auto_user: false,
is_string_repr: false,
max_length: 0,
choices: &[],
choice_labels: &[],
default: "",
is_multichoice: false,
unique: false,
on_delete: crate::orm::FkAction::NoAction,
on_update: crate::orm::FkAction::NoAction,
index: false,
auto_now_add: false,
auto_uuid: false,
auto_now: false,
trim: false,
lowercase: false,
case_insensitive: false,
help: "",
example: "",
widget: None,
min: None,
max: None,
text_format: ::core::option::Option::None,
slug_from: ::core::option::Option::None,
},
crate::orm::FieldSpec {
name: "body",
ty: crate::orm::SqlType::Text,
primary_key: false,
nullable: false,
supported_backends: &[],
fk_target: None,
noform: false,
privileged: false,
private: false,
secret: false,
db_constraint: true,
noedit: false,
auto_user_add: false,
auto_user: false,
is_string_repr: false,
max_length: 0,
choices: &[],
choice_labels: &[],
default: "",
is_multichoice: false,
unique: false,
on_delete: crate::orm::FkAction::NoAction,
on_update: crate::orm::FkAction::NoAction,
index: false,
auto_now_add: false,
auto_uuid: false,
auto_now: false,
trim: false,
lowercase: false,
case_insensitive: false,
help: "",
example: "",
widget: None,
min: None,
max: None,
text_format: ::core::option::Option::None,
slug_from: ::core::option::Option::None,
},
crate::orm::FieldSpec {
name: "published_at",
ty: crate::orm::SqlType::Timestamptz,
primary_key: false,
nullable: true,
supported_backends: &[],
fk_target: None,
noform: false,
privileged: false,
private: false,
secret: false,
db_constraint: true,
noedit: false,
auto_user_add: false,
auto_user: false,
is_string_repr: false,
max_length: 0,
choices: &[],
choice_labels: &[],
default: "",
is_multichoice: false,
unique: false,
on_delete: crate::orm::FkAction::NoAction,
on_update: crate::orm::FkAction::NoAction,
index: false,
auto_now_add: false,
auto_uuid: false,
auto_now: false,
trim: false,
lowercase: false,
case_insensitive: false,
help: "",
example: "",
widget: None,
min: None,
max: None,
text_format: ::core::option::Option::None,
slug_from: ::core::option::Option::None,
},
];
fn primary_key(&self) -> i64 {
self.id
}
}
impl crate::orm::HydrateRelated for Post {
fn fk_id_for(&self, _field_name: &str) -> Option<serde_json::Value> {
None
}
fn hydrate_fk(&mut self, _field_name: &str, _row: &serde_json::Value) {}
}
#[allow(clippy::module_inception)]
pub mod post {
use super::Post;
use crate::orm::column::{IntCol, NullableDateTimeCol, StrCol};
pub const ID: IntCol<Post> = IntCol::new("id");
pub const TITLE: StrCol<Post> = StrCol::new("title");
pub const BODY: StrCol<Post> = StrCol::new("body");
pub const PUBLISHED_AT: NullableDateTimeCol<Post> = NullableDateTimeCol::new("published_at");
}