Skip to content

Commit ab765cd

Browse files
add rest
1 parent 0838015 commit ab765cd

File tree

11 files changed

+320
-192
lines changed

11 files changed

+320
-192
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ resolver = "2"
99
[workspace.package]
1010
rust-version = "1.71"
1111

12+
13+
1214
[workspace.dependencies]
1315
# supporting crates unrelated to postgres
1416
line_index = { path = "./lib/line_index", version = "0.0.0" }
1517
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
1618
tree-sitter = "0.20.10"
1719
tracing = "0.1.40"
20+
sqlx = { version = "0.8.2", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
1821

1922
# postgres specific crates
2023
pg_lexer = { path = "./crates/pg_lexer", version = "0.0.0" }
@@ -38,6 +41,7 @@ pg_lint = { path = "./crates/pg_lint", version = "0.0.0" }
3841
pg_workspace = { path = "./crates/pg_workspace", version = "0.0.0" }
3942
pg_lsp = { path = "./crates/lsp", version = "0.0.0" }
4043

44+
pg_test_utils = { path = "./crates/pg_test_utils", version = "0.0.0" }
4145
# parser = { path = "./crates/parser", version = "0.0.0" }
4246
# sql_parser = { path = "./crates/sql_parser", version = "0.0.0" }
4347
# sql_parser_codegen = { path = "./crates/sql_parser_codegen", version = "0.0.0" }

crates/pg_commands/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ edition = "2021"
55

66
[dependencies]
77
text-size = "1.1.1"
8-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
98
async-std = "1.12.0"
109
anyhow = "1.0.62"
11-
12-
[dev-dependencies]
10+
sqlx.workspace = true
1311

1412
[lib]
1513
doctest = false

crates/pg_inlay_hints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pg_type_resolver.workspace = true
1111
pg_syntax.workspace = true
1212
tree-sitter.workspace = true
1313
tree_sitter_sql.workspace = true
14-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
14+
sqlx.workspace = true
1515

1616
[dev-dependencies]
1717
async-std = "1.12.0"

crates/pg_lsp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ lsp-types = "0.95.0"
1616
serde = "1.0.195"
1717
serde_json = "1.0.114"
1818
anyhow = "1.0.81"
19-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
2019
async-std = "1.12.0"
2120
threadpool = "1.8.1"
2221
dashmap = "5.5.3"
2322
text-size = "1.1.1"
2423

2524
line_index.workspace = true
25+
sqlx.workspace = true
2626

2727
pg_hover.workspace = true
2828
pg_fs.workspace = true

crates/pg_schema_cache/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
87
async-std = { version = "1.12.0" }
98
serde = "1.0.195"
109
serde_json = "1.0.114"
1110

11+
sqlx.workspace = true
12+
1213
[lib]
1314
doctest = false

crates/pg_test_utils/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "pg_test_utils"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version.workspace = true
6+
7+
[dependencies]
8+
anyhow = "1.0.81"
9+
uuid = { version = "1.11.0", features = ["v4"] }
10+
11+
sqlx.workspace = true

crates/pg_test_utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod test_database;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use sqlx::{postgres::PgConnectOptions, Executor, PgPool};
2+
use uuid::Uuid;
3+
4+
// TODO: Work with proper config objects instead of a connection_string.
5+
// With the current implementation, we can't parse the password from the connection string.
6+
pub async fn get_new_test_db(connection_string: String, database_password: String) -> PgPool {
7+
let options_from_conn_str: PgConnectOptions = connection_string
8+
.parse()
9+
.expect("Invalid Connection String");
10+
11+
let options_without_db_name = PgConnectOptions::new()
12+
.host(options_from_conn_str.get_host())
13+
.port(options_from_conn_str.get_port())
14+
.username(options_from_conn_str.get_username())
15+
.password(&database_password);
16+
17+
let postgres = sqlx::PgPool::connect_with(options_without_db_name.clone())
18+
.await
19+
.expect("Unable to connect to test postgres instance");
20+
21+
let database_name = Uuid::new_v4().to_string();
22+
23+
postgres
24+
.execute(format!(r#"create database "{}";"#, database_name).as_str())
25+
.await
26+
.expect("Failed to create test database.");
27+
28+
sqlx::PgPool::connect_with(options_without_db_name.database(&database_name))
29+
.await
30+
.expect("Could not connect to test database")
31+
}

crates/pg_typecheck/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ pg_base_db.workspace = true
88
pg_schema_cache.workspace = true
99
pg_syntax.workspace = true
1010
pg_query_ext.workspace = true
11+
12+
sqlx.workspace = true
13+
1114
text-size = "1.1.1"
1215
async-std = "1.12.0"
13-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
16+
1417

1518
[dev-dependencies]
1619

crates/pg_workspace/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2021"
77
text-size = "1.1.1"
88
dashmap = "5.5.3"
99
async-std = "1.12.0"
10-
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
1110

1211
pg_base_db.workspace = true
1312
pg_fs.workspace = true
@@ -21,6 +20,7 @@ pg_schema_cache.workspace = true
2120

2221
tree-sitter.workspace = true
2322
tree_sitter_sql.workspace = true
23+
sqlx.workspace = true
2424

2525
[dev-dependencies]
2626

0 commit comments

Comments
 (0)