-
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
8 changed files
with
1,156 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
use entities::person::queries::{GetPersonByEmail, GetPersonById}; | ||
use scyllax::executor::create_session; | ||
use entities::person::{ | ||
model::UpsertPerson, | ||
queries::{GetPersonByEmail, GetPersonById}, | ||
}; | ||
use scyllax::prelude::*; | ||
use scyllax::{executor::create_session, util::v1_uuid}; | ||
use tracing_subscriber::prelude::*; | ||
|
||
pub mod entities; | ||
|
@@ -13,34 +16,37 @@ async fn main() -> anyhow::Result<()> { | |
.init(); | ||
|
||
let known_nodes = std::env::var("SCYLLA_NODES").unwrap_or_else(|_| String::new()); | ||
let known_nodes = known_nodes.split(",").collect::<Vec<_>>(); | ||
let known_nodes = known_nodes.split(',').collect::<Vec<_>>(); | ||
let default_keyspace = std::env::var("SCYLLA_DEFAULT_KEYSPACE").ok(); | ||
let session = create_session(known_nodes, default_keyspace).await?; | ||
let exectuor = Executor::with_session(session); | ||
|
||
// TODO: run init | ||
let executor = Executor::with_session(session); | ||
|
||
let by_email = GetPersonByEmail { | ||
email: "[email protected]".to_string(), | ||
}; | ||
let res_one = exectuor | ||
let res_one = executor | ||
.execute_select(by_email) | ||
.await? | ||
.expect("person not found"); | ||
tracing::debug!("query 1: {:?}", res_one); | ||
|
||
let by_id = GetPersonById { id: res_one.id }; | ||
let res_two = exectuor | ||
let res_two = executor | ||
.execute_select(by_id) | ||
.await? | ||
.expect("person not found"); | ||
tracing::debug!("query 2: {:?}", res_two); | ||
|
||
assert_eq!(res_one, res_two); | ||
|
||
let test = exectuor.session.execute(r##"insert into person(id, email, "createdAt") values (b4ee3e46-46ce-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now()));"##, ()) | ||
.await?.rows(); | ||
tracing::debug!("test: {:?}", test); | ||
let create = UpsertPerson { | ||
id: v1_uuid(), | ||
email: MaybeUnset::Set("[email protected]".to_string()), | ||
age: MaybeUnset::Set(Some(21)), | ||
created_at: MaybeUnset::Unset, | ||
}; | ||
let res_three = executor.execute_upsert(create).await?; | ||
tracing::debug!("query 3: {:?}", res_three); | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ use scyllax; | |
create table person ( | ||
id timeuuid primary key, | ||
email text, | ||
age int, | ||
-- camel case for the sake of backwards compat | ||
"createdAt" timestamp | ||
); | ||
|
@@ -18,23 +19,23 @@ create materialized view person_by_email as | |
where email is not null and id is not null | ||
primary key (email, id); | ||
|
||
insert into person(id, email, "createdAt") values (e01e84d6-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e880a-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e89c2-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e8b2a-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e8db4-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e911a-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e9354-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e84d6-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e880a-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e89c2-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e8b2a-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e8db4-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e911a-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e9354-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e94e4-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e9854-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e9854-414c-11ee-be56-0242ac120002, '[email protected]', 25, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e99ee-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e9b60-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e9b60-414c-11ee-be56-0242ac120002, '[email protected]', 48, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e9cc8-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01e9e3a-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01e9e3a-414c-11ee-be56-0242ac120002, '[email protected]', 22, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01ea1d2-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01ea380-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01ea4f2-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01ea682-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01ea4f2-414c-11ee-be56-0242ac120002, '[email protected]', 26, toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01ea682-414c-11ee-be56-0242ac120002, '[email protected]', 18, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01ea81c-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01eab14-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); | ||
insert into person(id, email, age, "createdAt") values (e01eab14-414c-11ee-be56-0242ac120002, '[email protected]', 28, toUnixTimestamp(now())); | ||
insert into person(id, email, "createdAt") values (e01eaca4-414c-11ee-be56-0242ac120002, '[email protected]', toUnixTimestamp(now())); |
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
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