Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: use owned values for find by primary & partition key by value… #39

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ Resulting auto-generated migration query will be:
clustering_keys = [created_at, id],
global_secondary_indexes = [],
local_secondary_indexes = [],
table_options = #r"
WITH CLUSTERING ORDER BY (created_at DESC)
table_options = r#"
CLUSTERING ORDER BY (created_at DESC)
AND gc_grace_seconds = 86400
";
"#
)]
#[derive(Serialize, Deserialize, Default)]
pub struct Commit {...}
```
* ⚠️ If table exists, table options will result in alter table query that without
`CLUSTERING ORDER` and `COMPACT STORAGE` options.

Model dropping is not added. If you removed model, you need to drop table manuall
Model dropping is not added. If you removed model, you need to drop table manually.

* ### Running migration
```bash
Expand Down
4 changes: 2 additions & 2 deletions charybdis-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "charybdis_macros"
rust-version = "1.75.0"
version = "0.6.2"
version = "0.7.0"
edition = "2021"
description = "Proc macro crate for Charybdis ORM"
repository = "https://github.com/nodecosmos/charybdis"
Expand All @@ -12,7 +12,7 @@ categories = ["database"]
proc-macro = true

[dependencies]
charybdis_parser = { version = "0.6.2", path = "../charybdis-parser" }
charybdis_parser = { version = "0.7.0", path = "../charybdis-parser" }
proc-macro2 = "1.0.81"
syn = { version = "2.0.60", features = ["full"] }
quote = "1.0.36"
Expand Down
4 changes: 2 additions & 2 deletions charybdis-migrate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "charybdis-migrate"
rust-version = "1.75.0"
version = "0.6.2"
version = "0.7.0"
edition = "2021"
description = "Automatic Migration Tool for Charybdis ORM"
repository = "https://github.com/nodecosmos/charybdis"
license = "MIT"
categories = ["database"]

[dependencies]
charybdis_parser = { version = "0.6.2", path = "../charybdis-parser" }
charybdis_parser = { version = "0.7.0", path = "../charybdis-parser" }
scylla = "0.13.0"
tokio = { version = "1.37.0", features = ["full"] }
serde_json = "1.0.116"
Expand Down
6 changes: 3 additions & 3 deletions charybdis-migrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ migrate --hosts <host> --keyspace <your_keyspace> --drop-and-replace (optional)
table_name = commits,
partition_keys = [object_id],
clustering_keys = [created_at, id],
table_options = #r"
WITH CLUSTERING ORDER BY (created_at DESC)
table_options = r#"
CLUSTERING ORDER BY (created_at DESC)
AND gc_grace_seconds = 86400
";
"#
)]
#[derive(Serialize, Deserialize, Default)]
pub struct Commit {...}
Expand Down
2 changes: 1 addition & 1 deletion charybdis-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "charybdis_parser"
rust-version = "1.75.0"
version = "0.6.2"
version = "0.7.0"
edition = "2021"
description = "Parser crate for Charybdis ORM"
repository = "https://github.com/nodecosmos/charybdis"
Expand Down
4 changes: 2 additions & 2 deletions charybdis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "charybdis"
rust-version = "1.75.0"
version = "0.6.2"
version = "0.7.0"
edition = "2021"
description = "High-Performance ORM for ScyllaDB"
repository = "https://github.com/nodecosmos/charybdis"
Expand All @@ -11,7 +11,7 @@ categories = ["database"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
charybdis_macros = { version = "0.6.2", path = "../charybdis-macros" }
charybdis_macros = { version = "0.7.0", path = "../charybdis-macros" }
chrono = { version = "0.4.38", features = ["serde"] }
futures = "0.3.30"
num-bigint = "0.4.4"
Expand Down
8 changes: 4 additions & 4 deletions charybdis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ Resulting auto-generated migration query will be:
clustering_keys = [created_at, id],
global_secondary_indexes = [],
local_secondary_indexes = [],
table_options = #r"
WITH CLUSTERING ORDER BY (created_at DESC)
table_options = r#"
CLUSTERING ORDER BY (created_at DESC)
AND gc_grace_seconds = 86400
";
"#
)]
#[derive(Serialize, Deserialize, Default)]
pub struct Commit {...}
```
* ⚠️ If table exists, table options will result in alter table query that without
`CLUSTERING ORDER` and `COMPACT STORAGE` options.

Model dropping is not added. If you removed model, you need to drop table manuall
Model dropping is not added. If you removed model, you need to drop table manually.

* ### Running migration
```bash
Expand Down
36 changes: 22 additions & 14 deletions charybdis/src/operations/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,34 @@ pub trait Find: BaseModel {
CharybdisQuery::new(query, QueryValue::Owned(values))
}

fn find_by_primary_key_value(value: &Self::PrimaryKey) -> CharybdisQuery<Self::PrimaryKey, Self, ModelRow<Self>> {
CharybdisQuery::new(Self::FIND_BY_PRIMARY_KEY_QUERY, QueryValue::Ref(value))
fn find_by_primary_key_value<'a>(
value: Self::PrimaryKey,
) -> CharybdisQuery<'a, Self::PrimaryKey, Self, ModelRow<Self>> {
CharybdisQuery::new(Self::FIND_BY_PRIMARY_KEY_QUERY, QueryValue::Owned(value))
}

fn maybe_find_by_primary_key_value(
value: &Self::PrimaryKey,
) -> CharybdisQuery<Self::PrimaryKey, Self, OptionalModelRow<Self>> {
CharybdisQuery::new(Self::FIND_BY_PRIMARY_KEY_QUERY, QueryValue::Ref(value))
fn maybe_find_by_primary_key_value<'a>(
value: Self::PrimaryKey,
) -> CharybdisQuery<'a, Self::PrimaryKey, Self, OptionalModelRow<Self>> {
CharybdisQuery::new(Self::FIND_BY_PRIMARY_KEY_QUERY, QueryValue::Owned(value))
}

fn find_by_partition_key_value(
value: &Self::PartitionKey,
) -> CharybdisQuery<Self::PartitionKey, Self, ModelStream<Self>> {
CharybdisQuery::new(Self::FIND_BY_PARTITION_KEY_QUERY, QueryValue::Ref(value))
fn find_by_partition_key_value<'a>(
value: Self::PartitionKey,
) -> CharybdisQuery<'a, Self::PartitionKey, Self, ModelStream<Self>> {
CharybdisQuery::new(Self::FIND_BY_PARTITION_KEY_QUERY, QueryValue::Owned(value))
}

fn find_first_by_partition_key_value(
value: &Self::PartitionKey,
) -> CharybdisQuery<Self::PartitionKey, Self, ModelRow<Self>> {
CharybdisQuery::new(Self::FIND_FIRST_BY_PARTITION_KEY_QUERY, QueryValue::Ref(value))
fn find_first_by_partition_key_value<'a>(
value: Self::PartitionKey,
) -> CharybdisQuery<'a, Self::PartitionKey, Self, ModelRow<Self>> {
CharybdisQuery::new(Self::FIND_FIRST_BY_PARTITION_KEY_QUERY, QueryValue::Owned(value))
}

fn find_by_partition_key_value_paged<'a>(
value: Self::PartitionKey,
) -> CharybdisQuery<'a, Self::PartitionKey, Self, ModelPaged<Self>> {
CharybdisQuery::new(Self::FIND_BY_PARTITION_KEY_QUERY, QueryValue::Owned(value))
}

fn find_by_primary_key(&self) -> CharybdisQuery<Self::PrimaryKey, Self, ModelRow<Self>> {
Expand Down