Support Up to 6 Values Composite Primary Key (#353)
* Support up to 6 composite primary key * Test [issues] * Test [issues]
This commit is contained in:
parent
41e345c3a8
commit
1229287fd8
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
@ -316,7 +316,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
path: [86, 249, 262, 319, 324]
|
path: [86, 249, 262, 319, 324, 352]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ futures-util = { version = "^0.3" }
|
|||||||
log = { version = "^0.4", optional = true }
|
log = { version = "^0.4", optional = true }
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-orm-macros = { version = "^0.4.0", path = "sea-orm-macros", optional = true }
|
sea-orm-macros = { version = "^0.4.0", path = "sea-orm-macros", optional = true }
|
||||||
sea-query = { version = "^0.19.0", features = ["thread-safe"] }
|
sea-query = { version = "^0.19.0", git = "https://github.com/SeaQL/sea-query.git", branch = "sea-orm/issues/352", features = ["thread-safe"] }
|
||||||
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
serde_json = { version = "^1", optional = true }
|
serde_json = { version = "^1", optional = true }
|
||||||
|
11
issues/352/Cargo.toml
Normal file
11
issues/352/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[workspace]
|
||||||
|
# A separate workspace
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "sea-orm-issues-352"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls" ]}
|
18
issues/352/src/binary_primary_key.rs
Normal file
18
issues/352/src/binary_primary_key.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_2: String,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
8
issues/352/src/main.rs
Normal file
8
issues/352/src/main.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
mod unary_primary_key;
|
||||||
|
mod binary_primary_key;
|
||||||
|
mod ternary_primary_key;
|
||||||
|
mod quaternary_primary_key;
|
||||||
|
mod quinary_primary_key;
|
||||||
|
mod senary_primary_key;
|
||||||
|
|
||||||
|
pub fn main() {}
|
22
issues/352/src/quaternary_primary_key.rs
Normal file
22
issues/352/src/quaternary_primary_key.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_2: String,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_3: f64,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_4: Uuid,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
24
issues/352/src/quinary_primary_key.rs
Normal file
24
issues/352/src/quinary_primary_key.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_2: String,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_3: f64,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_4: Uuid,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_5: DateTime,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
26
issues/352/src/senary_primary_key.rs
Normal file
26
issues/352/src/senary_primary_key.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_2: String,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_3: f64,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_4: Uuid,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_5: DateTime,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_6: DateTimeWithTimeZone,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
20
issues/352/src/ternary_primary_key.rs
Normal file
20
issues/352/src/ternary_primary_key.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_2: String,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_3: f64,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
16
issues/352/src/unary_primary_key.rs
Normal file
16
issues/352/src/unary_primary_key.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "model")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id_1: i32,
|
||||||
|
pub owner: String,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
@ -451,6 +451,48 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B, C, D, E> TryGetableMany for (A, B, C, D, E)
|
||||||
|
where
|
||||||
|
A: TryGetable,
|
||||||
|
B: TryGetable,
|
||||||
|
C: TryGetable,
|
||||||
|
D: TryGetable,
|
||||||
|
E: TryGetable,
|
||||||
|
{
|
||||||
|
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError> {
|
||||||
|
try_get_many_with_slice_len_of(5, cols)?;
|
||||||
|
Ok((
|
||||||
|
A::try_get(res, pre, &cols[0])?,
|
||||||
|
B::try_get(res, pre, &cols[1])?,
|
||||||
|
C::try_get(res, pre, &cols[2])?,
|
||||||
|
D::try_get(res, pre, &cols[3])?,
|
||||||
|
E::try_get(res, pre, &cols[4])?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A, B, C, D, E, F> TryGetableMany for (A, B, C, D, E, F)
|
||||||
|
where
|
||||||
|
A: TryGetable,
|
||||||
|
B: TryGetable,
|
||||||
|
C: TryGetable,
|
||||||
|
D: TryGetable,
|
||||||
|
E: TryGetable,
|
||||||
|
F: TryGetable,
|
||||||
|
{
|
||||||
|
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError> {
|
||||||
|
try_get_many_with_slice_len_of(6, cols)?;
|
||||||
|
Ok((
|
||||||
|
A::try_get(res, pre, &cols[0])?,
|
||||||
|
B::try_get(res, pre, &cols[1])?,
|
||||||
|
C::try_get(res, pre, &cols[2])?,
|
||||||
|
D::try_get(res, pre, &cols[3])?,
|
||||||
|
E::try_get(res, pre, &cols[4])?,
|
||||||
|
F::try_get(res, pre, &cols[5])?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn try_get_many_with_slice_len_of(len: usize, cols: &[String]) -> Result<(), TryGetError> {
|
fn try_get_many_with_slice_len_of(len: usize, cols: &[String]) -> Result<(), TryGetError> {
|
||||||
if cols.len() < len {
|
if cols.len() < len {
|
||||||
Err(TryGetError::DbErr(DbErr::Query(format!(
|
Err(TryGetError::DbErr(DbErr::Query(format!(
|
||||||
@ -501,6 +543,8 @@ macro_rules! try_from_u64_err {
|
|||||||
try_from_u64_err!(A, B);
|
try_from_u64_err!(A, B);
|
||||||
try_from_u64_err!(A, B, C);
|
try_from_u64_err!(A, B, C);
|
||||||
try_from_u64_err!(A, B, C, D);
|
try_from_u64_err!(A, B, C, D);
|
||||||
|
try_from_u64_err!(A, B, C, D, E);
|
||||||
|
try_from_u64_err!(A, B, C, D, E, F);
|
||||||
|
|
||||||
macro_rules! try_from_u64_numeric {
|
macro_rules! try_from_u64_numeric {
|
||||||
( $type: ty ) => {
|
( $type: ty ) => {
|
||||||
@ -540,10 +584,28 @@ macro_rules! try_from_u64_string {
|
|||||||
|
|
||||||
try_from_u64_string!(String);
|
try_from_u64_string!(String);
|
||||||
|
|
||||||
|
try_from_u64_err!(bool);
|
||||||
|
try_from_u64_err!(f32);
|
||||||
|
try_from_u64_err!(f64);
|
||||||
try_from_u64_err!(Vec<u8>);
|
try_from_u64_err!(Vec<u8>);
|
||||||
|
|
||||||
#[cfg(feature = "with-uuid")]
|
#[cfg(feature = "with-json")]
|
||||||
try_from_u64_err!(uuid::Uuid);
|
try_from_u64_err!(serde_json::Value);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-chrono")]
|
||||||
|
try_from_u64_err!(chrono::NaiveDate);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-chrono")]
|
||||||
|
try_from_u64_err!(chrono::NaiveTime);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-chrono")]
|
||||||
|
try_from_u64_err!(chrono::NaiveDateTime);
|
||||||
|
|
||||||
#[cfg(feature = "with-chrono")]
|
#[cfg(feature = "with-chrono")]
|
||||||
try_from_u64_err!(chrono::DateTime<chrono::FixedOffset>);
|
try_from_u64_err!(chrono::DateTime<chrono::FixedOffset>);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-rust_decimal")]
|
||||||
|
try_from_u64_err!(rust_decimal::Decimal);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-uuid")]
|
||||||
|
try_from_u64_err!(uuid::Uuid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user