Skip to content

Commit

Permalink
fix: tests and include test migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko committed Oct 9, 2023
1 parent 36b6d92 commit 8739804
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
migrations
!test/migrations
16 changes: 8 additions & 8 deletions example/src/entities/person/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ mod test {

#[test]
fn test_pks() {
assert_eq!(PersonEntity::pks(), vec!["id".to_string()]);
assert_eq!(PersonEntity::pks(), vec![r#""id""#.to_string()]);
}

#[test]
fn test_keys() {
assert_eq!(
PersonEntity::keys(),
vec![
"id".to_string(),
"email".to_string(),
"age".to_string(),
"data".to_string(),
"kind".to_string(),
"\"createdAt\"".to_string()
r#""id""#.to_string(),
r#""email""#.to_string(),
r#""age""#.to_string(),
r#""data""#.to_string(),
r#""kind""#.to_string(),
r#""createdAt""#.to_string()
]
);
}
Expand All @@ -84,7 +84,7 @@ mod test {

assert_eq!(
query,
r#"update person set email = :email, age = :age, data = :data, kind = :kind, "createdAt" = :created_at where id = :id;"#
r#"update person set "email" = :email, "age" = :age, "data" = :data, "kind" = :kind, "createdAt" = :created_at where "id" = :id;"#
);

let mut result_values = SerializedValues::new();
Expand Down
6 changes: 3 additions & 3 deletions example/src/entities/person/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod test {

assert_eq!(
GetPersonById::query(),
r#"select id, email, age, data, kind, "createdAt" from person where id = :id limit 1"#
r#"select "id", "email", "age", "data", "kind", "createdAt" from person where id = :id limit 1"#
);
}

Expand All @@ -76,7 +76,7 @@ mod test {

assert_eq!(
GetPeopleByIds::query(),
r#"select id, email, age, data, kind, "createdAt" from person where id in :ids limit :limit"#
r#"select "id", "email", "age", "data", "kind", "createdAt" from person where id in :ids limit :rowlimit"#
);
}

Expand All @@ -88,7 +88,7 @@ mod test {

assert_eq!(
GetPersonByEmail::query(),
r#"select id, email, age, data, kind, "createdAt" from person_by_email where email = :email limit 1"#
r#"select "id", "email", "age", "data", "kind", "createdAt" from person_by_email where email = :email limit 1"#
);
}

Expand Down
10 changes: 5 additions & 5 deletions example/src/entities/person_login/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod test {
fn test_pks() {
assert_eq!(
PersonLoginEntity::pks(),
vec!["id".to_string(), "person_id".to_string()]
vec![r#""id""#.to_string(), r#""person_id""#.to_string()]
);
}

Expand All @@ -34,9 +34,9 @@ mod test {
assert_eq!(
PersonLoginEntity::keys(),
vec![
"id".to_string(),
"person_id".to_string(),
"count".to_string()
r#""id""#.to_string(),
r#""person_id""#.to_string(),
r#""count""#.to_string()
]
);
}
Expand All @@ -54,7 +54,7 @@ mod test {

assert_eq!(
query,
r#"update person_login set count = count + :count where id = :id and person_id = :person_id;"#
r#"update person_login set "count" = "count" + :count where "id" = :id and "person_id" = :person_id;"#
);

let mut result_values = SerializedValues::new();
Expand Down
2 changes: 1 addition & 1 deletion example/src/entities/person_login/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod test {

assert_eq!(
GetPersonLoginById::query(),
r#"select id, person_id, count from person_login where id = :id limit 1"#
r#"select "id", "person_id", "count" from person_login where id = :id limit 1"#
);
}

Expand Down
2 changes: 1 addition & 1 deletion scyllax-parser/src/where.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Parses where clauses in CQL statements
//! ```
//! ```ignore
//! where_clause: `relation` ( AND `relation` )*
//! relation: `column_name` `operator` `term`
//! : '(' `column_name` ( ',' `column_name` )* ')' `operator` `tuple_literal`
Expand Down
1 change: 1 addition & 0 deletions test/migrations/20231009224357_init/down.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- DROP TABLE test;
33 changes: 33 additions & 0 deletions test/migrations/20231009224357_init/up.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
create keyspace if not exists scyllax with replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};

create table if not exists scyllax.person (
id timeuuid primary key,
email text,
age int,
data text, -- json type
kind int,
-- camel case for the sake of backwards compat
"createdAt" timestamp
);

create materialized view if not exists scyllax.person_by_email as
select *
from person
where email is not null and id is not null
primary key (email, id);

insert into scyllax.person(id, email, age, data, kind, "createdAt") values (e01e84d6-414c-11ee-be56-0242ac120002, '[email protected]', 25, '{"foo":"bar"}', 0, toUnixTimestamp(now()));

insert into scyllax.person(id, email, age, kind, "createdAt") values (e01e880a-414c-11ee-be56-0242ac120002, '[email protected]', 25, 1, toUnixTimestamp(now()));

create table if not exists scyllax.person_login (
id timeuuid,
person_id uuid,
count counter,
primary key ((id), person_id)
);

update scyllax.person_login set count = count + 0 where id = 42dcfcde-5420-11ee-8c99-0242ac120002 and person_id = e01e84d6-414c-11ee-be56-0242ac120002;

0 comments on commit 8739804

Please sign in to comment.