Resign Iden
This commit is contained in:
parent
8ab34882bd
commit
19b95eb64b
@ -3,8 +3,7 @@ use sea_orm::{
|
||||
ModelTrait, QueryResult, Related, RelationDef, RelationTrait, Select, TypeErr, Value, PrimaryKeyTrait
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Iden)]
|
||||
#[iden = "cake"]
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct Entity;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
@ -13,13 +12,13 @@ pub struct Model {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Name,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
@ -39,6 +38,20 @@ impl EntityTrait for Entity {
|
||||
type Relation = Relation;
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Entity {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Entity {
|
||||
fn as_str(&self) -> &str {
|
||||
"cake"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl ModelTrait for Model {
|
||||
type Column = Column;
|
||||
@ -65,6 +78,13 @@ impl ModelTrait for Model {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Column {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Column {
|
||||
fn as_str(&self) -> &str {
|
||||
@ -86,6 +106,14 @@ impl ColumnTrait for Column {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for PrimaryKey {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for PrimaryKey {
|
||||
fn as_str(&self) -> &str {
|
||||
|
@ -3,8 +3,7 @@ use sea_orm::{
|
||||
ModelTrait, QueryResult, RelationDef, RelationTrait, TypeErr, Value, PrimaryKeyTrait
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Iden)]
|
||||
#[iden = "fruit"]
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct Entity;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
@ -14,14 +13,14 @@ pub struct Model {
|
||||
pub cake_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Name,
|
||||
CakeId,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
@ -39,6 +38,20 @@ impl EntityTrait for Entity {
|
||||
type Relation = Relation;
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Entity {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Entity {
|
||||
fn as_str(&self) -> &str {
|
||||
"fruit"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl ModelTrait for Model {
|
||||
type Column = Column;
|
||||
@ -68,6 +81,13 @@ impl ModelTrait for Model {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Column {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Column {
|
||||
fn as_str(&self) -> &str {
|
||||
@ -91,6 +111,13 @@ impl ColumnTrait for Column {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for PrimaryKey {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for PrimaryKey {
|
||||
fn as_str(&self) -> &str {
|
||||
|
@ -7,8 +7,12 @@ use sea_query::{Expr, Iden, IntoIden, Value};
|
||||
use std::fmt::Debug;
|
||||
pub use strum::IntoEnumIterator as Iterable;
|
||||
|
||||
pub trait IdenStatic: Iden + Copy + Debug + 'static {
|
||||
fn as_str(&self) -> &str;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait EntityTrait: Iden + Default + Debug + 'static {
|
||||
pub trait EntityTrait: IdenStatic + Default {
|
||||
type Model: ModelTrait;
|
||||
|
||||
type Column: ColumnTrait + Iterable;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::EntityTrait;
|
||||
use crate::{IdenStatic, EntityTrait};
|
||||
pub use sea_query::ColumnType;
|
||||
use sea_query::{Expr, Iden, SimpleExpr, Value};
|
||||
use std::fmt::Debug;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
macro_rules! bind_oper {
|
||||
@ -15,14 +15,6 @@ macro_rules! bind_oper {
|
||||
};
|
||||
}
|
||||
|
||||
pub trait IdenStatic: Iden + Copy + Debug + 'static {
|
||||
fn as_str(&self) -> &str;
|
||||
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ColumnTrait: IdenStatic {
|
||||
type Entity: EntityTrait;
|
||||
|
||||
|
@ -3,8 +3,7 @@ use crate::{
|
||||
ModelTrait, QueryResult, Related, RelationDef, RelationTrait, Select, TypeErr, Value, PrimaryKeyTrait
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Iden)]
|
||||
#[iden = "cake"]
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct Entity;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
@ -13,13 +12,13 @@ pub struct Model {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Name,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
@ -39,6 +38,20 @@ impl EntityTrait for Entity {
|
||||
type Relation = Relation;
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Entity {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Entity {
|
||||
fn as_str(&self) -> &str {
|
||||
"cake"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl ModelTrait for Model {
|
||||
type Column = Column;
|
||||
@ -65,6 +78,13 @@ impl ModelTrait for Model {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Column {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Column {
|
||||
fn as_str(&self) -> &str {
|
||||
@ -86,6 +106,14 @@ impl ColumnTrait for Column {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for PrimaryKey {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for PrimaryKey {
|
||||
fn as_str(&self) -> &str {
|
||||
|
@ -3,8 +3,7 @@ use crate::{
|
||||
ModelTrait, QueryResult, RelationDef, RelationTrait, TypeErr, Value, PrimaryKeyTrait
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Iden)]
|
||||
#[iden = "fruit"]
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct Entity;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
@ -14,14 +13,14 @@ pub struct Model {
|
||||
pub cake_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Name,
|
||||
CakeId,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Iden, EnumIter)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
@ -39,6 +38,20 @@ impl EntityTrait for Entity {
|
||||
type Relation = Relation;
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Entity {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Entity {
|
||||
fn as_str(&self) -> &str {
|
||||
"fruit"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl ModelTrait for Model {
|
||||
type Column = Column;
|
||||
@ -68,6 +81,13 @@ impl ModelTrait for Model {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for Column {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for Column {
|
||||
fn as_str(&self) -> &str {
|
||||
@ -91,6 +111,13 @@ impl ColumnTrait for Column {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl Iden for PrimaryKey {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement with derive macro
|
||||
impl IdenStatic for PrimaryKey {
|
||||
fn as_str(&self) -> &str {
|
||||
|
Loading…
x
Reference in New Issue
Block a user