-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
228 additions
and
275 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use scylla::frame::value::{CqlTimestamp, CqlTimeuuid}; | ||
use scylla::serialize::value::SerializeCql; | ||
use scyllax::prelude::*; | ||
|
||
/// Represents data from a person | ||
|
@@ -26,7 +28,7 @@ pub enum PersonKind { | |
pub struct PersonEntity { | ||
/// The id of the person | ||
#[entity(primary_key)] | ||
pub id: uuid::Uuid, | ||
pub id: CqlTimeuuid, | ||
/// The email address of the person | ||
pub email: String, | ||
/// The age of the person | ||
|
@@ -37,15 +39,15 @@ pub struct PersonEntity { | |
pub kind: PersonKind, | ||
/// The date the person was created | ||
#[entity(rename = "createdAt")] | ||
pub created_at: i64, | ||
#[scylla(rename = "createdAt")] | ||
pub created_at: CqlTimestamp, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use crate::entities::person::model::UpsertPerson; | ||
use pretty_assertions::assert_eq; | ||
use scylla::frame::value::SerializedValues; | ||
|
||
#[test] | ||
fn test_pks() { | ||
|
@@ -66,98 +68,4 @@ mod test { | |
] | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_upsert() { | ||
let upsert = UpsertPerson { | ||
id: v1_uuid(), | ||
email: MaybeUnset::Set("[email protected]".to_string()), | ||
age: MaybeUnset::Unset, | ||
kind: MaybeUnset::Set(PersonKind::Parent), | ||
data: MaybeUnset::Set(Some(PersonData { | ||
stripe_id: Some("stripe_id".to_string()), | ||
})), | ||
created_at: MaybeUnset::Unset, | ||
}; | ||
|
||
let query = <UpsertPerson as Query>::query(); | ||
let values = <UpsertPerson as Query>::bind(&upsert).unwrap(); | ||
|
||
assert_eq!( | ||
query, | ||
r#"update person set "email" = :email, "age" = :age, "data" = :data, "kind" = :kind, "createdAt" = :created_at where "id" = :id;"# | ||
); | ||
|
||
let mut result_values = SerializedValues::new(); | ||
result_values | ||
.add_named_value("email", &upsert.email) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("age", &upsert.age) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("data", &upsert.data) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("kind", &upsert.kind) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("created_at", &upsert.created_at) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("id", &upsert.id) | ||
.expect("failed to add value"); | ||
|
||
assert_eq!(values, result_values); | ||
} | ||
|
||
#[test] | ||
fn test_upsert_ttl() { | ||
let upsert = UpsertPersonWithTTL { | ||
id: v1_uuid(), | ||
email: MaybeUnset::Set("[email protected]".to_string()), | ||
age: MaybeUnset::Unset, | ||
kind: MaybeUnset::Set(PersonKind::Parent), | ||
data: MaybeUnset::Set(Some(PersonData { | ||
stripe_id: Some("stripe_id".to_string()), | ||
})), | ||
created_at: MaybeUnset::Unset, | ||
|
||
set_ttl: 300, | ||
}; | ||
|
||
let query = <UpsertPersonWithTTL as Query>::query(); | ||
let values = <UpsertPersonWithTTL as Query>::bind(&upsert).unwrap(); | ||
|
||
assert_eq!( | ||
query, | ||
r#"update person using ttl :set_ttl set "email" = :email, "age" = :age, "data" = :data, "kind" = :kind, "createdAt" = :created_at where "id" = :id;"# | ||
); | ||
|
||
let mut result_values = SerializedValues::new(); | ||
result_values | ||
.add_named_value("email", &upsert.email) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("age", &upsert.age) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("data", &upsert.data) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("kind", &upsert.kind) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("created_at", &upsert.created_at) | ||
.expect("failed to add value"); | ||
result_values | ||
.add_named_value("id", &upsert.id) | ||
.expect("failed to add value"); | ||
|
||
result_values | ||
.add_named_value("set_ttl", &upsert.set_ttl) | ||
.expect("failed to add value"); | ||
|
||
assert_eq!(values, result_values); | ||
} | ||
} |
Oops, something went wrong.