Skip to content

Commit 897b62e

Browse files
fix(schema_cache): return results
1 parent 652da2b commit 897b62e

File tree

8 files changed

+16
-18
lines changed

8 files changed

+16
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pg_schema_cache/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ version = "0.0.0"
1212

1313

1414
[dependencies]
15+
anyhow.workspace = true
1516
async-std = { version = "1.12.0" }
17+
futures-util = "0.3.31"
1618
serde.workspace = true
1719
serde_json.workspace = true
1820

crates/pg_schema_cache/src/functions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct Function {
6969
impl SchemaCacheItem for Function {
7070
type Item = Function;
7171

72-
async fn load(pool: &PgPool) -> Vec<Function> {
72+
async fn load(pool: &PgPool) -> Result<Vec<Function>, sqlx::Error> {
7373
sqlx::query_as!(
7474
Function,
7575
r#"
@@ -179,6 +179,5 @@ from
179179
)
180180
.fetch_all(pool)
181181
.await
182-
.unwrap()
183182
}
184183
}

crates/pg_schema_cache/src/schema_cache.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::future::join;
2-
1+
use anyhow::Context;
32
use sqlx::postgres::PgPool;
43

54
use crate::functions::Function;
@@ -22,23 +21,23 @@ impl SchemaCache {
2221
SchemaCache::default()
2322
}
2423

25-
pub async fn load(pool: &PgPool) -> SchemaCache {
26-
let (schemas, tables, functions, types, versions) = join!(
24+
pub async fn load(pool: &PgPool) -> anyhow::Result<SchemaCache> {
25+
let (schemas, tables, functions, types, versions) = futures_util::try_join!(
2726
Schema::load(pool),
2827
Table::load(pool),
2928
Function::load(pool),
3029
PostgresType::load(pool),
3130
Version::load(pool),
3231
)
33-
.await;
32+
.with_context(|| format!("Unable to load Schema Cache"))?;
3433

35-
SchemaCache {
34+
Ok(SchemaCache {
3635
schemas,
3736
tables,
3837
functions,
3938
types,
4039
versions,
41-
}
40+
})
4241
}
4342

4443
/// Applies an AST node to the repository
@@ -72,7 +71,7 @@ impl SchemaCache {
7271
pub trait SchemaCacheItem {
7372
type Item;
7473

75-
async fn load(pool: &PgPool) -> Vec<Self::Item>;
74+
async fn load(pool: &PgPool) -> Result<Vec<Self::Item>, sqlx::Error>;
7675
}
7776

7877
#[cfg(test)]

crates/pg_schema_cache/src/schemas.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Schema {
1212
impl SchemaCacheItem for Schema {
1313
type Item = Schema;
1414

15-
async fn load(pool: &PgPool) -> Vec<Schema> {
15+
async fn load(pool: &PgPool) -> Result<Vec<Schema>, sqlx::Error> {
1616
sqlx::query_as!(
1717
Schema,
1818
r#"select
@@ -33,6 +33,5 @@ where
3333
)
3434
.fetch_all(pool)
3535
.await
36-
.unwrap()
3736
}
3837
}

crates/pg_schema_cache/src/tables.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct Table {
4141
impl SchemaCacheItem for Table {
4242
type Item = Table;
4343

44-
async fn load(pool: &PgPool) -> Vec<Table> {
44+
async fn load(pool: &PgPool) -> Result<Vec<Table>, sqlx::Error> {
4545
sqlx::query_as!(
4646
Table,
4747
r#"SELECT
@@ -87,6 +87,5 @@ group by
8787
)
8888
.fetch_all(pool)
8989
.await
90-
.unwrap()
9190
}
9291
}

crates/pg_schema_cache/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct PostgresType {
5050
impl SchemaCacheItem for PostgresType {
5151
type Item = PostgresType;
5252

53-
async fn load(pool: &PgPool) -> Vec<PostgresType> {
53+
async fn load(pool: &PgPool) -> Result<Vec<PostgresType>, sqlx::Error> {
5454
sqlx::query_as!(
5555
PostgresType,
5656
r#"select
@@ -103,6 +103,5 @@ where
103103
)
104104
.fetch_all(pool)
105105
.await
106-
.unwrap()
107106
}
108107
}

crates/pg_schema_cache/src/versions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Version {
1313
impl SchemaCacheItem for Version {
1414
type Item = Version;
1515

16-
async fn load(pool: &PgPool) -> Vec<Version> {
16+
async fn load(pool: &PgPool) -> Result<Vec<Version>, sqlx::Error> {
1717
sqlx::query_as!(
1818
Version,
1919
r#"select
@@ -29,7 +29,6 @@ impl SchemaCacheItem for Version {
2929
)
3030
.fetch_all(pool)
3131
.await
32-
.unwrap()
3332
}
3433

3534
/*

0 commit comments

Comments
 (0)