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

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pg_completions/Cargo.toml

+3-1
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

+2
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

+4-7
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

+1-1
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

+7-1
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

+1-2
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

-20
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

+10-14
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

+1-2
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

+1-2
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

+1-2
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

+1-2
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
/*

crates/pg_typecheck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async-std = "1.12.0"
2424

2525

2626
[dev-dependencies]
27+
pg_test_utils.workspace = true
2728

2829
[lib]
2930
doctest = false

crates/pg_typecheck/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,21 @@ pub async fn check_sql<'a>(params: TypecheckerParams<'a>) -> Vec<TypeError> {
8585
#[cfg(test)]
8686
mod tests {
8787
use async_std::task::block_on;
88-
use sqlx::PgPool;
88+
use pg_test_utils::test_database::get_new_test_db;
8989

9090
use crate::{check_sql, TypecheckerParams};
9191

9292
#[test]
93-
fn test_check_sql() {
93+
fn test_basic_type() {
9494
let input = "select id, unknown from contact;";
9595

96-
let conn_string = std::env::var("DATABASE_URL").unwrap();
97-
98-
let pool = block_on(PgPool::connect(conn_string.as_str())).unwrap();
96+
let test_db = block_on(get_new_test_db());
9997

10098
let root = pg_query_ext::parse(input).unwrap();
10199
let ast = pg_syntax::parse_syntax(input, &root).ast;
102100

103101
let errs = block_on(check_sql(TypecheckerParams {
104-
conn: &pool,
102+
conn: &test_db,
105103
sql: input,
106104
ast: &root,
107105
enriched_ast: Some(&ast),
@@ -111,6 +109,6 @@ mod tests {
111109

112110
let e = &errs[0];
113111

114-
assert_eq!(&input[e.range.unwrap()], "unknown");
112+
assert_eq!(&input[e.range.unwrap()], "contact");
115113
}
116114
}

crates/pg_workspace_new/src/workspace/server.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ impl WorkspaceServer {
128128
tracing::info!("Reloading schema cache");
129129
// TODO return error if db connection is not available
130130
if let Some(c) = self.connection.read().unwrap().get_pool() {
131-
let schema_cache = run_async(async move {
132-
// TODO load should return a Result
133-
SchemaCache::load(&c).await
134-
})?;
131+
let maybe_schema_cache = run_async(async move { SchemaCache::load(&c).await })?;
132+
let schema_cache = maybe_schema_cache?;
135133

136134
let mut cache = self.schema_cache.write().unwrap();
137135
*cache = schema_cache;

0 commit comments

Comments
 (0)