WIP
This commit is contained in:
parent
8cfa14233d
commit
484da8f6b6
@ -27,6 +27,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,18 @@ impl Entity {
|
|||||||
format_ident!("{}", auto_increment)
|
format_ident!("{}", auto_increment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_primary_key_rs_type(&self) -> TokenStream {
|
||||||
|
if let Some(primary_key) = self.primary_keys.first() {
|
||||||
|
self.columns
|
||||||
|
.iter()
|
||||||
|
.find(|col| col.name.eq(&primary_key.name))
|
||||||
|
.unwrap()
|
||||||
|
.get_rs_type()
|
||||||
|
} else {
|
||||||
|
TokenStream::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_conjunct_relations_via_snake_case(&self) -> Vec<Ident> {
|
pub fn get_conjunct_relations_via_snake_case(&self) -> Vec<Ident> {
|
||||||
self.conjunct_relations
|
self.conjunct_relations
|
||||||
.iter()
|
.iter()
|
||||||
@ -151,7 +163,7 @@ mod tests {
|
|||||||
columns: vec![
|
columns: vec![
|
||||||
Column {
|
Column {
|
||||||
name: "id".to_owned(),
|
name: "id".to_owned(),
|
||||||
col_type: ColumnType::String(None),
|
col_type: ColumnType::Integer(None),
|
||||||
auto_increment: false,
|
auto_increment: false,
|
||||||
not_null: false,
|
not_null: false,
|
||||||
unique: false,
|
unique: false,
|
||||||
@ -373,6 +385,16 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_primary_key_rs_type() {
|
||||||
|
let entity = setup();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
entity.get_primary_key_rs_type().to_string(),
|
||||||
|
entity.columns[0].get_rs_type().to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_conjunct_relations_via_snake_case() {
|
fn test_get_conjunct_relations_via_snake_case() {
|
||||||
let entity = setup();
|
let entity = setup();
|
||||||
|
@ -173,8 +173,11 @@ impl EntityWriter {
|
|||||||
|
|
||||||
pub fn gen_impl_primary_key(entity: &Entity) -> TokenStream {
|
pub fn gen_impl_primary_key(entity: &Entity) -> TokenStream {
|
||||||
let primary_key_auto_increment = entity.get_primary_key_auto_increment();
|
let primary_key_auto_increment = entity.get_primary_key_auto_increment();
|
||||||
|
let value_type = entity.get_primary_key_rs_type();
|
||||||
quote! {
|
quote! {
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = #value_type;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
#primary_key_auto_increment
|
#primary_key_auto_increment
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::str::FromStr;
|
|
||||||
use crate::{EntityName, IdenStatic, Iterable};
|
use crate::{EntityName, IdenStatic, Iterable};
|
||||||
use sea_query::{DynIden, Expr, SeaRc, SelectStatement, SimpleExpr, Value};
|
use sea_query::{DynIden, Expr, SeaRc, SelectStatement, SimpleExpr, Value};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ColumnDef {
|
pub struct ColumnDef {
|
||||||
|
@ -2,6 +2,8 @@ use super::{ColumnTrait, IdenStatic, Iterable};
|
|||||||
|
|
||||||
//LINT: composite primary key cannot auto increment
|
//LINT: composite primary key cannot auto increment
|
||||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
||||||
|
type ValueType: Sized;
|
||||||
|
|
||||||
fn auto_increment() -> bool;
|
fn auto_increment() -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ pub enum PrimaryKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryKeyTrait for PrimaryKey {
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
type ValueType = i32;
|
||||||
|
|
||||||
fn auto_increment() -> bool {
|
fn auto_increment() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user