Skip to content

Commit

Permalink
chore: update to scylla@0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko committed Feb 12, 2024
1 parent 01ace3c commit e2aac6e
Show file tree
Hide file tree
Showing 28 changed files with 228 additions and 275 deletions.
60 changes: 12 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ homepage = "https://github.com/trufflehq/scyllax#readme"
readme = "README.md"

[workspace.dependencies]
scyllax-macros = { verison = "0.1.1", path = "./scyllax-macros" }
scyllax-macros-core = { verison = "0.1.1", path = "./scyllax-macros-core" }
scyllax-parser = { verison = "0.1.1", path = "./scyllax-parser" }
scyllax-macros = { verison = "0.2.0-alpha", path = "./scyllax-macros" }
scyllax-macros-core = { verison = "0.2.0-alpha", path = "./scyllax-macros-core" }
scyllax-parser = { verison = "0.2.0-alpha", path = "./scyllax-parser" }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json", "tracing-log", "parking_lot"] }
tokio = { version = "1", features = ["full", "tracing"] }
scylla = { version = "0.10" }
scylla = { version = "0.12" }
serde_json = { version = "1", features = ["preserve_order"] }
serde = { version = "1", features = ["derive"] }
uuid = { version = "1", features = ["serde", "v1", "std", "fast-rng"] }
Expand Down
3 changes: 2 additions & 1 deletion example/src/bin/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use example::entities::post::{
model::{LikeData, UpsertPost},
queries::{GetPostById, PostQueries},
};
use scylla::frame::value::CqlTimeuuid;
use scyllax::{executor::create_session, util::v1_uuid};
use scyllax::{json::Json, prelude::*};
use tracing_subscriber::prelude::*;
Expand All @@ -29,7 +30,7 @@ async fn main() -> anyhow::Result<()> {
let session = create_session(known_nodes, default_keyspace).await?;
let executor = Executor::<PostQueries>::new(Arc::new(session)).await?;

let post_id = v1_uuid();
let post_id = CqlTimeuuid::from(v1_uuid());
let insert_body = UpsertPost {
id: post_id,
title: MaybeUnset::Set("Hello, World!".to_string()),
Expand Down
102 changes: 5 additions & 97 deletions example/src/entities/person/model.rs
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
Expand Down Expand Up @@ -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
Expand All @@ -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;

Check warning on line 49 in example/src/entities/person/model.rs

View workflow job for this annotation

GitHub Actions / Run the example

unused import: `crate::entities::person::model::UpsertPerson`
use pretty_assertions::assert_eq;
use scylla::frame::value::SerializedValues;

#[test]
fn test_pks() {
Expand All @@ -66,98 +68,4 @@ mod test {
]
);
}

#[test]
fn test_upsert() {
let upsert = UpsertPerson {
id: v1_uuid(),
email: MaybeUnset::Set("foo21@scyllax.local".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("foo21@scyllax.local".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);
}
}
Loading

0 comments on commit e2aac6e

Please sign in to comment.