Test derive FromJsonQueryResult
This commit is contained in:
parent
8064097639
commit
97ee0a9703
@ -100,7 +100,7 @@ impl DeriveValueType {
|
||||
|
||||
quote!(
|
||||
#[automatically_derived]
|
||||
impl From<#name> for Value {
|
||||
impl std::convert::From<#name> for Value {
|
||||
fn from(source: #name) -> Self {
|
||||
source.0.into()
|
||||
}
|
||||
|
19
tests/common/features/json_vec_derive.rs
Normal file
19
tests/common/features/json_vec_derive.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::FromJsonQueryResult;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "json_vec")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub str_vec: StringVec,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
|
||||
pub struct StringVec(pub Vec<String>);
|
@ -13,6 +13,7 @@ pub mod event_trigger;
|
||||
pub mod insert_default;
|
||||
pub mod json_struct;
|
||||
pub mod json_vec;
|
||||
pub mod json_vec_derive;
|
||||
pub mod metadata;
|
||||
pub mod pi;
|
||||
pub mod repository;
|
||||
|
@ -14,6 +14,7 @@ async fn main() -> Result<(), DbErr> {
|
||||
let ctx = TestContext::new("json_vec_tests").await;
|
||||
create_tables(&ctx.db).await?;
|
||||
insert_json_vec(&ctx.db).await?;
|
||||
insert_json_vec_derive(&ctx.db).await?;
|
||||
ctx.delete().await;
|
||||
|
||||
Ok(())
|
||||
@ -38,3 +39,23 @@ pub async fn insert_json_vec(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_json_vec_derive(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
let json_vec = json_vec_derive::Model {
|
||||
id: 2,
|
||||
str_vec: json_vec_derive::StringVec(vec!["4".to_string(), "5".to_string(), "6".to_string()]),
|
||||
};
|
||||
|
||||
let result = json_vec.clone().into_active_model().insert(db).await?;
|
||||
|
||||
assert_eq!(result, json_vec);
|
||||
|
||||
let model = json_vec_derive::Entity::find()
|
||||
.filter(json_vec_derive::Column::Id.eq(json_vec.id))
|
||||
.one(db)
|
||||
.await?;
|
||||
|
||||
assert_eq!(model, Some(json_vec));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user