-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
byte_primary_key_tests.rs
90 lines (72 loc) 路 2.47 KB
/
byte_primary_key_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection};
#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
let ctx = TestContext::new("byte_primary_key_tests").await;
create_tables(&ctx.db).await?;
create_and_update(&ctx.db).await?;
ctx.delete().await;
Ok(())
}
pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
use common::features::byte_primary_key::*;
let model = Model {
id: vec![1, 2, 3],
value: "First Row".to_owned(),
};
let res = Entity::insert(model.clone().into_active_model())
.exec(db)
.await?;
assert_eq!(Entity::find().one(db).await?, Some(model.clone()));
assert_eq!(res.last_insert_id, model.id);
let updated_active_model = ActiveModel {
value: Set("First Row (Updated)".to_owned()),
..model.clone().into_active_model()
};
let update_res = Entity::update(updated_active_model.clone())
.filter(Column::Id.eq(vec![1_u8, 2_u8, 4_u8])) // annotate it as Vec<u8> explicitly
.exec(db)
.await;
assert_eq!(update_res, Err(DbErr::RecordNotUpdated));
let update_res = Entity::update(updated_active_model)
.filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly
.exec(db)
.await?;
assert_eq!(
update_res,
Model {
id: vec![1, 2, 3],
value: "First Row (Updated)".to_owned(),
}
);
assert_eq!(
Entity::find()
.filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly
.one(db)
.await?,
Some(Model {
id: vec![1, 2, 3],
value: "First Row (Updated)".to_owned(),
})
);
assert_eq!(
Entity::find()
.filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly
.into_values::<_, Column>()
.one(db)
.await?,
Some((vec![1_u8, 2_u8, 3_u8], "First Row (Updated)".to_owned(),))
);
assert_eq!(
Entity::find()
.filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly
.into_tuple()
.one(db)
.await?,
Some((vec![1_u8, 2_u8, 3_u8], "First Row (Updated)".to_owned(),))
);
Ok(())
}