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

feat, refactor: Query Collections, read_query, electric slide #13

Merged
merged 3 commits into from
Oct 6, 2023
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
9 changes: 9 additions & 0 deletions Cargo.lock

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

29 changes: 4 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["example", "scyllax-cli", "scyllax-macros", "scyllax-parser"]
members = ["example", "scyllax", "scyllax-cli", "scyllax-macros", "scyllax-macros-core", "scyllax-parser"]
resolver = "2"

[workspace.package]
Expand All @@ -15,31 +15,10 @@ authors = [
homepage = "https://github.com/trufflehq/scyllax#readme"
readme = "README.md"

[package]
name = "scyllax"
readme = "README.md"
description = "A SQLx and Discord inspired query system for Scylla"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }

[dependencies]
anyhow = { workspace = true }
async-trait = "0.1"
getrandom = "0.2"
mac_address = "1"
once_cell = "1"
scylla = { workspace = true }
scyllax-macros = { version = "0.1.8-alpha", path = "./scyllax-macros" }
thiserror = "1"
tracing = { workspace = true }
uuid = { workspace = true }

[workspace.dependencies]
scyllax-macros = { verison = "0.1.8-alpha", path = "scyllax-macros" }
scyllax-macros = { verison = "0.1.8-alpha", path = "./scyllax-macros" }
scyllax-macros-core = { verison = "0.1.8-alpha", path = "./scyllax-macros-core" }
scyllax-parser = { verison = "0.1.8-alpha", path = "./scyllax-parser" }
anyhow = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json", "tracing-log", "parking_lot"] }
Expand Down
6 changes: 4 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ script = '''
echo # things required by `cargo make audit`
cargo install cargo-audit

echo # things required by `cargo release`
cargo install cargo-release

echo # things required by `cargo make sort-deps`
cargo install cargo-sort
'''
Expand Down Expand Up @@ -168,6 +171,5 @@ command = "cargo"
args = ["audit"]

[tasks.dev-book]
cwd = "book"
command = "mdbook"
args = ["serve"]
args = ["serve", "book"]
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub struct PersonEntity {
pub created_at: i64,
}
```
### 2. Select queries
With the [`select_query`] attribute, it's easy to define select queries.
### 2. Read queries
With the [`read_query`] attribute, it's easy to define select queries.
```rust,ignore
#[select_query(
query = "select * from person where id = ? limit 1",
entity_type = "PersonEntity"
#[read_query(
query = "select * from person where id = :id limit 1",
return_type = "PersonEntity"
)]
pub struct GetPersonById {
pub id: Uuid,
Expand All @@ -42,11 +42,10 @@ pub struct PersonEntity {
```

## Features
- [x] Select Queries
- [x] Upsert Queries (https://github.com/trufflehq/scyllax/pull/1)
- [x] Delete Queries
- [x] Read Queries
- [x] Write Queries (https://github.com/trufflehq/scyllax/pull/1)
- [ ] Request Coalescing
- [ ] Compile-time Select Query Validation
- [x] Compile-time Select Query Validation
- ensure the where constraints exist on the struct
- ensure the where constraints are the same type as the struct
- [ ] Runtime Query Validation (structure matches schema)
Expand Down
2 changes: 1 addition & 1 deletion book/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ fn main() {
let default_keyspace = std::env::var("SCYLLA_DEFAULT_KEYSPACE").ok();

let session = create_session(known_nodes, default_keyspace).await?;
let executor = Executor::with_session(session);
let executor = Executor::<UserQueries>::new(session).await?;
}
```
2 changes: 2 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
- [Select Queries](./select_queries/README.md)
- [Delete Queries](./delete_queries/README.md)
- [Upsert Queries](./upsert_queries/README.md)
- [Query Collections](./query_collections/README.md)
- [Example](./example/README.md)
4 changes: 2 additions & 2 deletions book/src/delete_queries/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Delete Queries
Writing delete queries, which is pretty much the same as [Select Queries](../select_queries/index.html), is incredibly easy with the `delete_query` macro.

Simply create a struct with the fields you want to select, and annotate it with the `#[delete_query]` macro.
Simply create a struct with the fields you want to select, and annotate it with the `#[write_query]` macro.

```rust
#use scyllax::prelude::*;
Expand All @@ -15,7 +15,7 @@ Simply create a struct with the fields you want to select, and annotate it with
# pub created_at: i64,
#}
#
#[delete_query(
#[write_query(
query = "delete from person where id = ?",
entity_type = "PersonEntity"
)]
Expand Down
4 changes: 4 additions & 0 deletions book/src/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Example
Are you looking for a real-life example of scyllax? You're in luck! The `exmaple` directory in our GitHub repository contains a full example of scyllax in action -- it's actually used to run tests!

[https://github.com/trufflehq/scyllax/tree/main/example](https://github.com/trufflehq/scyllax/tree/main/example)
33 changes: 33 additions & 0 deletions book/src/query_collections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Query Collections
Once you've made all your queries, you'll have to make a Query Collection. This is a struct that contains all your prepared queries. Scyllax provides the `create_query_collection` macro to make this easy.

```rust
use scyllax::prelude::*;
use super::model::UpsertPerson;

create_query_collection!(
PersonQueries,
[
GetPersonById,
GetPeopleByIds,
GetPersonByEmail,
DeletePersonById,
UpsertPerson,
]
);
```
Then, you use the Query Collection when you instantiate your Executor.

```rust
let executor = Executor::<PersonQueries>::new(session).await?;
```

Finally, you can run your queries.

```rust
let person = executor
.execute_read(&GetPersonById {
id: Uuid::new_v4(),
})
.await?;
```
2 changes: 1 addition & 1 deletion book/src/select_queries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Simply create a struct with the fields you want to select, and annotate it with
# pub created_at: i64,
#}
#
#[select_query(
#[read_query(
query = "select * from person where id = ? limit 1",
entity_type = "PersonEntity"
)]
Expand Down
40 changes: 40 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# configuration file for git-cliff (0.1.0)

[changelog]
header = "# Changelog\n\n"
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true

[git]
conventional_commits = true
filter_unconventional = true
commit_preprocessors = [
# replace issues with issue links
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/trufflehq/scyllax/issues/${2}))" },
]
commit_parsers = [
{ message = "^build", group = "Build" },
{ message = "^docs", group = "Documentation" },
{ message = "^feat", group = "Features" },
{ message = "^fix", group = "Bug Fixes" },
{ message = "^perf", group = "Performance" },
{ message = "^refactor", group = "Refactor" },
{ message = "^test", group = "Testing" },
{ message = "^ci", skip = true },
]
filter_commits = false
date_order = true
sort_commits = "oldest"
30 changes: 15 additions & 15 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "example"
description = "an example using scyllax"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
version.workspace = true
license.workspace = true
edition.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
publish = false

[dependencies]
anyhow = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
scylla = { workspace = true }
scyllax = { path = "../" }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
uuid = { workspace = true }
anyhow.workspace = true
serde.workspace = true
serde_json.workspace = true
scylla.workspace = true
scyllax = { path = "../scyllax" }
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true

[features]
default = ["integration"]
Expand Down
Loading