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: Convert Uuid IDs to StrongIds #4008

Open
wants to merge 1 commit into
base: sandbox
Choose a base branch
from
Open
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
154 changes: 114 additions & 40 deletions backend/api/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ quote = "1.0.18"
hashfn = "0.2.0"
csv = "1.1.6"
async-stripe = { version = "0.22.2", features = ["runtime-tokio-hyper-rustls"] }
strong_id = { version = "0.2.0" }

# project deps
ji_core = { path = "../ji_core", features = ["db"] }
Expand Down
35 changes: 23 additions & 12 deletions backend/api/src/db/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ order by index
}

#[instrument(skip(db))]
pub async fn get_exact(db: &sqlx::PgPool, ids: &[Uuid]) -> sqlx::Result<Vec<Category>> {
pub async fn get_exact(db: &sqlx::PgPool, ids: &[CategoryId]) -> sqlx::Result<Vec<Category>> {
sqlx::query!(
//language=SQL
r#"
Expand All @@ -60,7 +60,7 @@ from category
inner join unnest($1::uuid[]) with ordinality t(id, ord) USING (id)
order by t.ord
"#,
ids
&ids.iter().map(|id| id.0).collect::<Vec<_>>(),
)
.fetch(db)
.map_ok(|it| Category {
Expand All @@ -81,11 +81,15 @@ order by t.ord
}

#[instrument(skip(db))]
pub async fn get_subtree(db: &sqlx::PgPool, ids: &[Uuid]) -> sqlx::Result<Vec<Category>> {
sqlx::query_file_as!(RawCategory, "query/category/get_subtree.sql", ids)
.fetch_all(db)
.await
.map(build_tree)
pub async fn get_subtree(db: &sqlx::PgPool, ids: &[CategoryId]) -> sqlx::Result<Vec<Category>> {
sqlx::query_file_as!(
RawCategory,
"query/category/get_subtree.sql",
&ids.iter().map(|id| id.0).collect::<Vec<_>>()
)
.fetch_all(db)
.await
.map(build_tree)
}

#[instrument(skip_all)]
Expand All @@ -110,11 +114,18 @@ order by index
}

#[instrument(skip_all)]
pub async fn get_ancestor_tree(db: &sqlx::PgPool, ids: &[Uuid]) -> sqlx::Result<Vec<Category>> {
sqlx::query_file_as!(RawCategory, "query/category/get_ancestor_tree.sql", ids)
.fetch_all(db)
.await
.map(build_tree)
pub async fn get_ancestor_tree(
db: &sqlx::PgPool,
ids: &[CategoryId],
) -> sqlx::Result<Vec<Category>> {
sqlx::query_file_as!(
RawCategory,
"query/category/get_ancestor_tree.sql",
&ids.iter().map(|id| id.0).collect::<Vec<_>>()
)
.fetch_all(db)
.await
.map(build_tree)
}

#[instrument(skip(db))]
Expand Down
76 changes: 67 additions & 9 deletions backend/pages/Cargo.lock

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

Loading