| Crates.io | senax-pgsql-parser |
| lib.rs | senax-pgsql-parser |
| version | 0.1.1 |
| created_at | 2025-11-16 11:49:04.741086+00 |
| updated_at | 2025-12-18 05:02:05.987647+00 |
| description | PostgreSQL database schema parser and DDL generator with PostGIS support |
| homepage | |
| repository | https://github.com/yossyX/senax-pgsql-parser |
| max_upload_size | |
| id | 1935432 |
| size | 112,054 |
A comprehensive PostgreSQL database schema parser and DDL generator with PostGIS support.
This code is AI-generated. The author does not fully understand all implementation details. Use at your own risk and verify the behavior thoroughly before using in production environments.
Add to your Cargo.toml:
[dependencies]
senax-pgsql-parser = "0.1.0"
use senax_pgsql_parser::{connect_to_database, get_database_schema};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let database_url = "postgresql://user:password@localhost/mydatabase";
let pool = connect_to_database(database_url).await?;
let schema = get_database_schema(&pool).await?;
println!("Successfully connected and parsed schema.");
println!("Found {} tables.", schema.tables.len());
for table in schema.tables {
println!("Table: {}.{}", table.table_schema, table.table_name);
for column in table.columns {
println!(" - {}: {}", column.column_name, column.data_type);
}
}
Ok(())
}
The tool automatically detects and uses the current PostgreSQL schema using SELECT current_schema(), ensuring accurate schema analysis within the active database context.
use senax_pgsql_parser::{connect_to_database, get_database_schema};
let pool = connect_to_database("postgresql://user:pass@localhost/db").await?;
let schema = get_database_schema(&pool).await?;
// Generate CREATE statements
let create_ddl = schema.to_create_ddl();
println!("{}", create_ddl);
// Generate DROP statements
let drop_ddl = schema.to_drop_ddl();
println!("{}", drop_ddl);
for table in &schema.tables {
println!("Table: {}", table.table_name);
// Primary keys
let pk_columns: Vec<_> = table.columns.iter()
.filter(|col| col.is_primary_key)
.collect();
// Foreign keys
for fk in &table.foreign_keys {
println!("FK: {} -> {}.{}",
fk.columns.join(","),
fk.referenced_table,
fk.referenced_columns.join(",")
);
}
// Indexes
for index in &table.indexes {
println!("Index: {} on {}", index.index_name, index.columns.join(","));
}
}
This project is licensed under either of
at your option.