Skip to content

Commit

Permalink
feat: Convert Uuid IDs to StrongIds
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnynotsolucky committed Jul 14, 2023
1 parent 5ccef63 commit a6405ae
Show file tree
Hide file tree
Showing 40 changed files with 544 additions and 222 deletions.
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

0 comments on commit a6405ae

Please sign in to comment.