Skip to main content

postgres_lsp_schema/
lib.rs

1pub mod catalog;
2
3use postgres_lsp_analysis::WorkspaceIndex;
4use tracing::info;
5
6pub use catalog::{CatalogError, DB_URI};
7
8/// Load schema from a live PostgreSQL database and merge into the workspace index.
9pub async fn load_database_schema(
10    database_url: &str,
11    index: &WorkspaceIndex,
12) -> Result<usize, CatalogError> {
13    let (client, connection) = tokio_postgres::connect(database_url, tokio_postgres::NoTls).await?;
14
15    // Spawn the connection handler.
16    tokio::spawn(async move {
17        if let Err(e) = connection.await {
18            tracing::error!("database connection error: {e}");
19        }
20    });
21
22    let symbols = catalog::load_catalog(&client).await?;
23    let count = symbols.len();
24
25    info!("loaded {count} symbols from database");
26    index.load_symbols(DB_URI, symbols);
27
28    Ok(count)
29}