Skip to content

Commit 9d77de0

Browse files
chore: resolve conflicts
2 parents 78ff716 + 97679c2 commit 9d77de0

File tree

16 files changed

+47
-65
lines changed

16 files changed

+47
-65
lines changed

Cargo.lock

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

crates/pg_completions/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ async-std = "1.12.0"
1717
text-size.workspace = true
1818

1919
pg_schema_cache.workspace = true
20-
pg_test_utils.workspace = true
2120
tree-sitter.workspace = true
2221
tree_sitter_sql.workspace = true
2322

2423
sqlx.workspace = true
2524

2625
tokio = { version = "1.41.1", features = ["full"] }
2726

27+
[dev-dependencies]
28+
pg_test_utils.workspace = true
29+
2830
[lib]
2931
doctest = false
3032

crates/pg_inlay_hints/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ tree_sitter_sql.workspace = true
2323

2424
[dev-dependencies]
2525
async-std = "1.12.0"
26+
pg_test_utils.workspace = true
27+
2628

2729
[lib]
2830
doctest = false

crates/pg_inlay_hints/src/functions_args.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn resolve_func_arg_hint(
8080
mod tests {
8181
use async_std::task::block_on;
8282
use pg_schema_cache::SchemaCache;
83-
use sqlx::PgPool;
83+
use pg_test_utils::test_database::get_new_test_db;
8484

8585
use crate::{
8686
functions_args::FunctionArgHint,
@@ -89,17 +89,14 @@ mod tests {
8989

9090
#[test]
9191
fn test_function_args() {
92+
let test_db = block_on(get_new_test_db());
9293
let input = "select lower('TEST')";
9394

94-
let conn_string = std::env::var("DATABASE_URL").unwrap();
95-
96-
let pool = block_on(PgPool::connect(conn_string.as_str())).unwrap();
97-
9895
let root = pg_query_ext::parse(input).unwrap();
99-
10096
let res = pg_syntax::parse_syntax(input, &root);
10197

102-
let schema_cache = block_on(SchemaCache::load(&pool));
98+
let schema_cache =
99+
block_on(SchemaCache::load(&test_db)).expect("Couldn't load Schema Cache");
103100

104101
let hints = FunctionArgHint::find_all(InlayHintsParams {
105102
ast: Some(&root),

crates/pg_lsp/src/db_connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl DbConnection {
4141
match res {
4242
Ok(not) => {
4343
if not.payload().to_string() == "reload schema" {
44-
let schema_cache = SchemaCache::load(&cloned_pool).await;
44+
let schema_cache = SchemaCache::load(&cloned_pool).await.unwrap();
4545
ide.write().await.set_schema_cache(schema_cache);
4646
};
4747
}

crates/pg_schema_cache/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ 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
18-
20+
pg_diagnostics.workspace = true
21+
pg_console.workspace = true
1922
sqlx.workspace = true
2023

24+
[dev-dependencies]
25+
pg_test_utils.workspace = true
26+
2127
[lib]
2228
doctest = false

crates/pg_schema_cache/src/functions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub struct Function {
109109
impl SchemaCacheItem for Function {
110110
type Item = Function;
111111

112-
async fn load(pool: &PgPool) -> Vec<Function> {
112+
async fn load(pool: &PgPool) -> Result<Vec<Function>, sqlx::Error> {
113113
sqlx::query_as!(
114114
Function,
115115
r#"
@@ -246,6 +246,5 @@ from
246246
)
247247
.fetch_all(pool)
248248
.await
249-
.unwrap()
250249
}
251250
}

crates/pg_schema_cache/src/lib.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! The schema cache
22
33
#![allow(dead_code)]
4-
#![feature(future_join)]
54

65
mod functions;
76
mod schema_cache;
@@ -10,25 +9,6 @@ mod tables;
109
mod types;
1110
mod versions;
1211

13-
use sqlx::postgres::PgPool;
14-
1512
pub use functions::{Behavior, Function, FunctionArg, FunctionArgs};
1613
pub use schema_cache::SchemaCache;
1714
pub use tables::{ReplicaIdentity, Table};
18-
19-
#[derive(Debug, Clone)]
20-
struct SchemaCacheManager {
21-
pub cache: SchemaCache,
22-
}
23-
24-
impl SchemaCacheManager {
25-
pub async fn init(pool: &PgPool) -> Self {
26-
SchemaCacheManager {
27-
cache: SchemaCache::load(pool).await,
28-
}
29-
}
30-
31-
pub async fn reload_cache(&mut self, pool: &PgPool) {
32-
self.cache = SchemaCache::load(pool).await;
33-
}
34-
}

crates/pg_schema_cache/src/schema_cache.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::future::join;
2-
31
use sqlx::postgres::PgPool;
42

53
use crate::functions::Function;
@@ -22,23 +20,22 @@ impl SchemaCache {
2220
SchemaCache::default()
2321
}
2422

25-
pub async fn load(pool: &PgPool) -> SchemaCache {
26-
let (schemas, tables, functions, types, versions) = join!(
23+
pub async fn load(pool: &PgPool) -> Result<SchemaCache, sqlx::Error> {
24+
let (schemas, tables, functions, types, versions) = futures_util::try_join!(
2725
Schema::load(pool),
2826
Table::load(pool),
2927
Function::load(pool),
3028
PostgresType::load(pool),
3129
Version::load(pool),
32-
)
33-
.await;
30+
)?;
3431

35-
SchemaCache {
32+
Ok(SchemaCache {
3633
schemas,
3734
tables,
3835
functions,
3936
types,
4037
versions,
41-
}
38+
})
4239
}
4340

4441
/// Applies an AST node to the repository
@@ -72,22 +69,21 @@ impl SchemaCache {
7269
pub trait SchemaCacheItem {
7370
type Item;
7471

75-
async fn load(pool: &PgPool) -> Vec<Self::Item>;
72+
async fn load(pool: &PgPool) -> Result<Vec<Self::Item>, sqlx::Error>;
7673
}
7774

7875
#[cfg(test)]
7976
mod tests {
80-
use sqlx::PgPool;
77+
use async_std::task::block_on;
78+
use pg_test_utils::test_database::get_new_test_db;
8179

8280
use crate::SchemaCache;
8381

8482
#[test]
8583
fn test_schema_cache() {
86-
let conn_string = std::env::var("DATABASE_URL").unwrap();
87-
88-
let pool = async_std::task::block_on(PgPool::connect(conn_string.as_str())).unwrap();
84+
let test_db = block_on(get_new_test_db());
8985

90-
async_std::task::block_on(SchemaCache::load(&pool));
86+
block_on(SchemaCache::load(&test_db)).expect("Couldn't load Schema Cache");
9187

9288
assert!(true);
9389
}

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
}

0 commit comments

Comments
 (0)