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