Codegen: update ColumnDef
This commit is contained in:
parent
cab4b5a3f7
commit
91023d06c5
@ -2,7 +2,7 @@ DROP TABLE IF EXISTS `cake`;
|
|||||||
|
|
||||||
CREATE TABLE `cake` (
|
CREATE TABLE `cake` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`name` varchar(255) DEFAULT NULL,
|
`name` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
@ -14,9 +14,10 @@ DROP TABLE IF EXISTS `fruit`;
|
|||||||
|
|
||||||
CREATE TABLE `fruit` (
|
CREATE TABLE `fruit` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`name` varchar(255) DEFAULT NULL,
|
`name` varchar(255) NOT NULL,
|
||||||
`cake_id` int DEFAULT NULL,
|
`cake_id` int DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`),
|
||||||
|
CONSTRAINT `fk-fruit-cake` FOREIGN KEY (`cake_id`) REFERENCES `cake` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
INSERT INTO `fruit` (`id`, `name`, `cake_id`) VALUES
|
INSERT INTO `fruit` (`id`, `name`, `cake_id`) VALUES
|
||||||
@ -36,7 +37,7 @@ DROP TABLE IF EXISTS `filling`;
|
|||||||
|
|
||||||
CREATE TABLE `filling` (
|
CREATE TABLE `filling` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`name` varchar(255) DEFAULT NULL,
|
`name` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
@ -50,7 +51,9 @@ DROP TABLE IF EXISTS `cake_filling`;
|
|||||||
CREATE TABLE `cake_filling` (
|
CREATE TABLE `cake_filling` (
|
||||||
`cake_id` int NOT NULL,
|
`cake_id` int NOT NULL,
|
||||||
`filling_id` int NOT NULL,
|
`filling_id` int NOT NULL,
|
||||||
PRIMARY KEY (`cake_id`, `filling_id`)
|
PRIMARY KEY (`cake_id`, `filling_id`),
|
||||||
|
CONSTRAINT `fk-cake_filling-cake` FOREIGN KEY (`cake_id`) REFERENCES `cake` (`id`),
|
||||||
|
CONSTRAINT `fk-cake_filling-filling` FOREIGN KEY (`filling_id`) REFERENCES `filling` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
INSERT INTO `cake_filling` (`cake_id`, `filling_id`) VALUES
|
INSERT INTO `cake_filling` (`cake_id`, `filling_id`) VALUES
|
||||||
|
@ -11,4 +11,4 @@ sea-orm-codegen = { path = "../../sea-orm-codegen" }
|
|||||||
sea-query = { path = "../../../sea-query" }
|
sea-query = { path = "../../../sea-query" }
|
||||||
strum = { version = "^0.20", features = [ "derive" ] }
|
strum = { version = "^0.20", features = [ "derive" ] }
|
||||||
serde_json = { version = "^1" }
|
serde_json = { version = "^1" }
|
||||||
quote = "1"
|
quote = { version = "^1" }
|
||||||
|
@ -14,7 +14,7 @@ impl EntityName for Entity {
|
|||||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: Option<String>,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
@ -42,10 +42,10 @@ pub enum Relation {
|
|||||||
|
|
||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(Some(11u32)),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(Some(255u32)),
|
Self::Name => ColumnType::String(Some(255u32)).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ pub enum Relation {
|
|||||||
|
|
||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::CakeId => ColumnType::Integer(Some(11u32)),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
Self::FillingId => ColumnType::Integer(Some(11u32)),
|
Self::FillingId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ impl EntityName for Entity {
|
|||||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: Option<String>,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
@ -41,10 +41,10 @@ pub enum Relation {
|
|||||||
|
|
||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(Some(11u32)),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(Some(255u32)),
|
Self::Name => ColumnType::String(Some(255u32)).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ impl EntityName for Entity {
|
|||||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: Option<String>,
|
pub name: String,
|
||||||
pub cake_id: Option<i32>,
|
pub cake_id: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ pub enum Relation {
|
|||||||
|
|
||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(Some(11u32)),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(Some(255u32)),
|
Self::Name => ColumnType::String(Some(255u32)).def(),
|
||||||
Self::CakeId => ColumnType::Integer(Some(11u32)),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0
|
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
|
||||||
pub struct Entity;
|
|
||||||
|
|
||||||
impl EntityName for Entity {
|
|
||||||
fn table_name(&self) -> &str {
|
|
||||||
"fruit_copy"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
|
||||||
pub struct Model {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: Option<String>,
|
|
||||||
pub cake_id: Option<i32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
||||||
pub enum Column {
|
|
||||||
Id,
|
|
||||||
Name,
|
|
||||||
CakeId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
|
||||||
pub enum PrimaryKey {
|
|
||||||
Id,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
|
||||||
fn auto_increment() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
||||||
pub enum Relation {}
|
|
||||||
|
|
||||||
impl ColumnTrait for Column {
|
|
||||||
type EntityName = Entity;
|
|
||||||
fn def(&self) -> ColumnType {
|
|
||||||
match self {
|
|
||||||
Self::Id => ColumnType::Integer(Some(11u32)),
|
|
||||||
Self::Name => ColumnType::String(Some(255u32)),
|
|
||||||
Self::CakeId => ColumnType::Integer(Some(11u32)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
match self {
|
|
||||||
_ => panic!("No RelationDef"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model {}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -4,4 +4,3 @@ pub mod cake;
|
|||||||
pub mod cake_filling;
|
pub mod cake_filling;
|
||||||
pub mod filling;
|
pub mod filling;
|
||||||
pub mod fruit;
|
pub mod fruit;
|
||||||
pub mod fruit_copy;
|
|
||||||
|
@ -4,4 +4,3 @@ pub use super::cake::Entity as Cake;
|
|||||||
pub use super::cake_filling::Entity as CakeFilling;
|
pub use super::cake_filling::Entity as CakeFilling;
|
||||||
pub use super::filling::Entity as Filling;
|
pub use super::filling::Entity as Filling;
|
||||||
pub use super::fruit::Entity as Fruit;
|
pub use super::fruit::Entity as Fruit;
|
||||||
pub use super::fruit_copy::Entity as FruitCopy;
|
|
||||||
|
@ -40,10 +40,10 @@ pub enum Relation {
|
|||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
|
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(None),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(None),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ pub enum Relation {
|
|||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
|
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::CakeId => ColumnType::Integer(None),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
Self::FillingId => ColumnType::Integer(None),
|
Self::FillingId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ pub enum Relation {}
|
|||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
|
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(None),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(None),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,11 @@ pub enum Relation {}
|
|||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
|
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer(None),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String(None),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
Self::CakeId => ColumnType::Integer(None),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ sea-orm = { path = "../", features = [ "sqlx-mysql", "runtime-async-std-native-t
|
|||||||
sea-schema = { path = "../../sea-schema", default-features = false, features = [ "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "writer" ] }
|
sea-schema = { path = "../../sea-schema", default-features = false, features = [ "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "writer" ] }
|
||||||
sea-query = { path = "../../sea-query", version = "^0.12" }
|
sea-query = { path = "../../sea-query", version = "^0.12" }
|
||||||
sqlx = { version = "^0.5", features = [ "mysql", "runtime-async-std-native-tls" ] }
|
sqlx = { version = "^0.5", features = [ "mysql", "runtime-async-std-native-tls" ] }
|
||||||
syn = { version = "1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
|
syn = { version = "^1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
|
||||||
quote = "1"
|
quote = "^1"
|
||||||
heck = "0.3"
|
heck = "^0.3"
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "^1"
|
||||||
|
@ -36,9 +36,9 @@ impl Column {
|
|||||||
ColumnType::SmallInteger(_) => format_ident!("i16"),
|
ColumnType::SmallInteger(_) => format_ident!("i16"),
|
||||||
ColumnType::Integer(_) => format_ident!("i32"),
|
ColumnType::Integer(_) => format_ident!("i32"),
|
||||||
ColumnType::BigInteger(_) => format_ident!("i64"),
|
ColumnType::BigInteger(_) => format_ident!("i64"),
|
||||||
ColumnType::Float(_)
|
ColumnType::Float(_) | ColumnType::Decimal(_) | ColumnType::Money(_) => {
|
||||||
| ColumnType::Decimal(_)
|
format_ident!("f32")
|
||||||
| ColumnType::Money(_) => format_ident!("f32"),
|
}
|
||||||
ColumnType::Double(_) => format_ident!("f64"),
|
ColumnType::Double(_) => format_ident!("f64"),
|
||||||
ColumnType::Binary(_) => format_ident!("Vec<u8>"),
|
ColumnType::Binary(_) => format_ident!("Vec<u8>"),
|
||||||
ColumnType::Boolean => format_ident!("bool"),
|
ColumnType::Boolean => format_ident!("bool"),
|
||||||
@ -49,72 +49,42 @@ impl Column {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_type(&self) -> TokenStream {
|
pub fn get_def(&self) -> TokenStream {
|
||||||
match &self.col_type {
|
match &self.col_type {
|
||||||
ColumnType::Char(s) => match s {
|
ColumnType::Char(s) => match s {
|
||||||
Some(s) => quote! { ColumnType::Char(Some(#s)) },
|
Some(s) => quote! { ColumnType::Char(Some(#s)).def() },
|
||||||
None => quote! { ColumnType::Char(None) },
|
None => quote! { ColumnType::Char(None).def() },
|
||||||
},
|
},
|
||||||
ColumnType::String(s) => match s {
|
ColumnType::String(s) => match s {
|
||||||
Some(s) => quote! { ColumnType::String(Some(#s)) },
|
Some(s) => quote! { ColumnType::String(Some(#s)).def() },
|
||||||
None => quote! { ColumnType::String(None) },
|
None => quote! { ColumnType::String(None).def() },
|
||||||
},
|
|
||||||
ColumnType::Text => quote! { ColumnType::Text },
|
|
||||||
ColumnType::TinyInteger(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::TinyInteger(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::TinyInteger(None) },
|
|
||||||
},
|
|
||||||
ColumnType::SmallInteger(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::SmallInteger(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::SmallInteger(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Integer(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::Integer(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::Integer(None) },
|
|
||||||
},
|
|
||||||
ColumnType::BigInteger(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::BigInteger(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::BigInteger(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Float(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::Float(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::Float(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Double(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::Double(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::Double(None) },
|
|
||||||
},
|
},
|
||||||
|
ColumnType::Text => quote! { ColumnType::Text.def() },
|
||||||
|
ColumnType::TinyInteger(s) => quote! { ColumnType::TinyInteger.def() },
|
||||||
|
ColumnType::SmallInteger(s) => quote! { ColumnType::SmallInteger.def() },
|
||||||
|
ColumnType::Integer(s) => quote! { ColumnType::Integer.def() },
|
||||||
|
ColumnType::BigInteger(s) => quote! { ColumnType::BigInteger.def() },
|
||||||
|
ColumnType::Float(s) => quote! { ColumnType::Float.def() },
|
||||||
|
ColumnType::Double(s) => quote! { ColumnType::Double.def() },
|
||||||
ColumnType::Decimal(s) => match s {
|
ColumnType::Decimal(s) => match s {
|
||||||
Some((s1, s2)) => quote! { ColumnType::Decimal(Some((#s1, #s2))) },
|
Some((s1, s2)) => quote! { ColumnType::Decimal(Some((#s1, #s2))).def() },
|
||||||
None => quote! { ColumnType::Decimal(None) },
|
None => quote! { ColumnType::Decimal(None).def() },
|
||||||
},
|
},
|
||||||
ColumnType::DateTime(s) => match s {
|
ColumnType::DateTime(s) => quote! { ColumnType::DateTime.def() },
|
||||||
Some(s) => quote! { ColumnType::DateTime(Some(#s)) },
|
ColumnType::Timestamp(s) => quote! { ColumnType::Timestamp.def() },
|
||||||
None => quote! { ColumnType::DateTime(None) },
|
ColumnType::Time(s) => quote! { ColumnType::Time.def() },
|
||||||
},
|
ColumnType::Date => quote! { ColumnType::Date.def() },
|
||||||
ColumnType::Timestamp(s) => match s {
|
ColumnType::Binary(s) => quote! { ColumnType::Binary.def() },
|
||||||
Some(s) => quote! { ColumnType::Timestamp(Some(#s)) },
|
ColumnType::Boolean => quote! { ColumnType::Boolean.def() },
|
||||||
None => quote! { ColumnType::Timestamp(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Time(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::Time(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::Time(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Date => quote! { ColumnType::Date },
|
|
||||||
ColumnType::Binary(s) => match s {
|
|
||||||
Some(s) => quote! { ColumnType::Binary(Some(#s)) },
|
|
||||||
None => quote! { ColumnType::Binary(None) },
|
|
||||||
},
|
|
||||||
ColumnType::Boolean => quote! { ColumnType::Boolean },
|
|
||||||
ColumnType::Money(s) => match s {
|
ColumnType::Money(s) => match s {
|
||||||
Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))) },
|
Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))).def() },
|
||||||
None => quote! { ColumnType::Money(None) },
|
None => quote! { ColumnType::Money(None).def() },
|
||||||
},
|
},
|
||||||
ColumnType::Json => quote! { ColumnType::Json },
|
ColumnType::Json => quote! { ColumnType::Json.def() },
|
||||||
ColumnType::JsonBinary => quote! { ColumnType::JsonBinary },
|
ColumnType::JsonBinary => quote! { ColumnType::JsonBinary.def() },
|
||||||
ColumnType::Custom(s) => {
|
ColumnType::Custom(s) => {
|
||||||
let s = s.to_string();
|
let s = s.to_string();
|
||||||
quote! { ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(#s))) }
|
quote! { ColumnType::Custom(#s.to_owned()).def() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,11 @@ impl Entity {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_column_types(&self) -> Vec<TokenStream> {
|
pub fn get_column_defs(&self) -> Vec<TokenStream> {
|
||||||
self.columns
|
self.columns
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|col| col.get_type())
|
.map(|col| col.get_def())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,14 +201,14 @@ impl EntityWriter {
|
|||||||
|
|
||||||
pub fn gen_impl_column_trait(entity: &Entity) -> TokenStream {
|
pub fn gen_impl_column_trait(entity: &Entity) -> TokenStream {
|
||||||
let column_names_camel_case = entity.get_column_names_camel_case();
|
let column_names_camel_case = entity.get_column_names_camel_case();
|
||||||
let column_types = entity.get_column_types();
|
let column_defs = entity.get_column_defs();
|
||||||
quote! {
|
quote! {
|
||||||
impl ColumnTrait for Column {
|
impl ColumnTrait for Column {
|
||||||
type EntityName = Entity;
|
type EntityName = Entity;
|
||||||
|
|
||||||
fn def(&self) -> ColumnType {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
#(Self::#column_names_camel_case => #column_types),*
|
#(Self::#column_names_camel_case => #column_defs),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ path = "src/lib.rs"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = { version = "1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
|
syn = { version = "^1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
|
||||||
quote = "1"
|
quote = "^1"
|
||||||
heck = "0.3"
|
heck = "^0.3"
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "^1"
|
||||||
|
@ -9,10 +9,10 @@ pub struct ColumnDef {
|
|||||||
pub(crate) indexed: bool,
|
pub(crate) indexed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ColumnType {
|
pub enum ColumnType {
|
||||||
Char,
|
Char(Option<u32>),
|
||||||
String,
|
String(Option<u32>),
|
||||||
Text,
|
Text,
|
||||||
TinyInteger,
|
TinyInteger,
|
||||||
SmallInteger,
|
SmallInteger,
|
||||||
@ -20,16 +20,17 @@ pub enum ColumnType {
|
|||||||
BigInteger,
|
BigInteger,
|
||||||
Float,
|
Float,
|
||||||
Double,
|
Double,
|
||||||
Decimal,
|
Decimal(Option<(u32, u32)>),
|
||||||
DateTime,
|
DateTime,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
Time,
|
Time,
|
||||||
Date,
|
Date,
|
||||||
Binary,
|
Binary,
|
||||||
Boolean,
|
Boolean,
|
||||||
Money,
|
Money(Option<(u32, u32)>),
|
||||||
Json,
|
Json,
|
||||||
JsonBinary,
|
JsonBinary,
|
||||||
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! bind_oper {
|
macro_rules! bind_oper {
|
||||||
@ -215,10 +216,10 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
|||||||
bind_vec_func!(is_not_in);
|
bind_vec_func!(is_not_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ColumnType> for ColumnDef {
|
impl ColumnType {
|
||||||
fn from(col_type: ColumnType) -> Self {
|
pub fn def(self) -> ColumnDef {
|
||||||
Self {
|
ColumnDef {
|
||||||
col_type,
|
col_type: self,
|
||||||
null: false,
|
null: false,
|
||||||
unique: false,
|
unique: false,
|
||||||
indexed: false,
|
indexed: false,
|
||||||
@ -229,8 +230,8 @@ impl From<ColumnType> for ColumnDef {
|
|||||||
impl Into<sea_query::ColumnType> for ColumnType {
|
impl Into<sea_query::ColumnType> for ColumnType {
|
||||||
fn into(self) -> sea_query::ColumnType {
|
fn into(self) -> sea_query::ColumnType {
|
||||||
match self {
|
match self {
|
||||||
Self::Char => sea_query::ColumnType::Char(None),
|
Self::Char(s) => sea_query::ColumnType::Char(s),
|
||||||
Self::String => sea_query::ColumnType::String(None),
|
Self::String(s) => sea_query::ColumnType::String(s),
|
||||||
Self::Text => sea_query::ColumnType::Text,
|
Self::Text => sea_query::ColumnType::Text,
|
||||||
Self::TinyInteger => sea_query::ColumnType::TinyInteger(None),
|
Self::TinyInteger => sea_query::ColumnType::TinyInteger(None),
|
||||||
Self::SmallInteger => sea_query::ColumnType::SmallInteger(None),
|
Self::SmallInteger => sea_query::ColumnType::SmallInteger(None),
|
||||||
@ -238,16 +239,19 @@ impl Into<sea_query::ColumnType> for ColumnType {
|
|||||||
Self::BigInteger => sea_query::ColumnType::BigInteger(None),
|
Self::BigInteger => sea_query::ColumnType::BigInteger(None),
|
||||||
Self::Float => sea_query::ColumnType::Float(None),
|
Self::Float => sea_query::ColumnType::Float(None),
|
||||||
Self::Double => sea_query::ColumnType::Double(None),
|
Self::Double => sea_query::ColumnType::Double(None),
|
||||||
Self::Decimal => sea_query::ColumnType::Decimal(None),
|
Self::Decimal(s) => sea_query::ColumnType::Decimal(s),
|
||||||
Self::DateTime => sea_query::ColumnType::DateTime(None),
|
Self::DateTime => sea_query::ColumnType::DateTime(None),
|
||||||
Self::Timestamp => sea_query::ColumnType::Timestamp(None),
|
Self::Timestamp => sea_query::ColumnType::Timestamp(None),
|
||||||
Self::Time => sea_query::ColumnType::Time(None),
|
Self::Time => sea_query::ColumnType::Time(None),
|
||||||
Self::Date => sea_query::ColumnType::Date,
|
Self::Date => sea_query::ColumnType::Date,
|
||||||
Self::Binary => sea_query::ColumnType::Binary(None),
|
Self::Binary => sea_query::ColumnType::Binary(None),
|
||||||
Self::Boolean => sea_query::ColumnType::Boolean,
|
Self::Boolean => sea_query::ColumnType::Boolean,
|
||||||
Self::Money => sea_query::ColumnType::Money(None),
|
Self::Money(s) => sea_query::ColumnType::Money(s),
|
||||||
Self::Json => sea_query::ColumnType::Json,
|
Self::Json => sea_query::ColumnType::Json,
|
||||||
Self::JsonBinary => sea_query::ColumnType::JsonBinary,
|
Self::JsonBinary => sea_query::ColumnType::JsonBinary,
|
||||||
|
Self::Custom(s) => {
|
||||||
|
sea_query::ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(&s)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,8 +259,8 @@ impl Into<sea_query::ColumnType> for ColumnType {
|
|||||||
impl From<sea_query::ColumnType> for ColumnType {
|
impl From<sea_query::ColumnType> for ColumnType {
|
||||||
fn from(col_type: sea_query::ColumnType) -> Self {
|
fn from(col_type: sea_query::ColumnType) -> Self {
|
||||||
match col_type {
|
match col_type {
|
||||||
sea_query::ColumnType::Char(_) => Self::Char,
|
sea_query::ColumnType::Char(s) => Self::Char(s),
|
||||||
sea_query::ColumnType::String(_) => Self::String,
|
sea_query::ColumnType::String(s) => Self::String(s),
|
||||||
sea_query::ColumnType::Text => Self::Text,
|
sea_query::ColumnType::Text => Self::Text,
|
||||||
sea_query::ColumnType::TinyInteger(_) => Self::TinyInteger,
|
sea_query::ColumnType::TinyInteger(_) => Self::TinyInteger,
|
||||||
sea_query::ColumnType::SmallInteger(_) => Self::SmallInteger,
|
sea_query::ColumnType::SmallInteger(_) => Self::SmallInteger,
|
||||||
@ -264,17 +268,17 @@ impl From<sea_query::ColumnType> for ColumnType {
|
|||||||
sea_query::ColumnType::BigInteger(_) => Self::BigInteger,
|
sea_query::ColumnType::BigInteger(_) => Self::BigInteger,
|
||||||
sea_query::ColumnType::Float(_) => Self::Float,
|
sea_query::ColumnType::Float(_) => Self::Float,
|
||||||
sea_query::ColumnType::Double(_) => Self::Double,
|
sea_query::ColumnType::Double(_) => Self::Double,
|
||||||
sea_query::ColumnType::Decimal(_) => Self::Decimal,
|
sea_query::ColumnType::Decimal(s) => Self::Decimal(s),
|
||||||
sea_query::ColumnType::DateTime(_) => Self::DateTime,
|
sea_query::ColumnType::DateTime(_) => Self::DateTime,
|
||||||
sea_query::ColumnType::Timestamp(_) => Self::Timestamp,
|
sea_query::ColumnType::Timestamp(_) => Self::Timestamp,
|
||||||
sea_query::ColumnType::Time(_) => Self::Time,
|
sea_query::ColumnType::Time(_) => Self::Time,
|
||||||
sea_query::ColumnType::Date => Self::Date,
|
sea_query::ColumnType::Date => Self::Date,
|
||||||
sea_query::ColumnType::Binary(_) => Self::Binary,
|
sea_query::ColumnType::Binary(_) => Self::Binary,
|
||||||
sea_query::ColumnType::Boolean => Self::Boolean,
|
sea_query::ColumnType::Boolean => Self::Boolean,
|
||||||
sea_query::ColumnType::Money(_) => Self::Money,
|
sea_query::ColumnType::Money(s) => Self::Money(s),
|
||||||
sea_query::ColumnType::Json => Self::Json,
|
sea_query::ColumnType::Json => Self::Json,
|
||||||
sea_query::ColumnType::JsonBinary => Self::JsonBinary,
|
sea_query::ColumnType::JsonBinary => Self::JsonBinary,
|
||||||
sea_query::ColumnType::Custom(_) => panic!("custom column type unsupported"),
|
sea_query::ColumnType::Custom(s) => Self::Custom(s.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ impl ColumnTrait for Column {
|
|||||||
|
|
||||||
fn def(&self) -> ColumnDef {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer.into(),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String.into(),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ impl ColumnTrait for Column {
|
|||||||
|
|
||||||
fn def(&self) -> ColumnDef {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::CakeId => ColumnType::Integer.into(),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
Self::FillingId => ColumnType::Integer.into(),
|
Self::FillingId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ impl ColumnTrait for Column {
|
|||||||
|
|
||||||
fn def(&self) -> ColumnDef {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer.into(),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String.into(),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,9 @@ impl ColumnTrait for Column {
|
|||||||
|
|
||||||
fn def(&self) -> ColumnDef {
|
fn def(&self) -> ColumnDef {
|
||||||
match self {
|
match self {
|
||||||
Self::Id => ColumnType::Integer.into(),
|
Self::Id => ColumnType::Integer.def(),
|
||||||
Self::Name => ColumnType::String.into(),
|
Self::Name => ColumnType::String(None).def(),
|
||||||
Self::CakeId => ColumnType::Integer.into(),
|
Self::CakeId => ColumnType::Integer.def(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user