Expand description
PostgreSQL Database Schema Parser
This crate provides functionality to read PostgreSQL database schema information, provide it as structured data, and generate DDL statements.
§Main Features
- Read table structures from PostgreSQL databases
- PostGIS extension support
- DDL generation (CREATE TABLE, DROP TABLE)
- Management of foreign key constraints, indexes, and CHECK constraints
- Accurate handling of Serial types
- Roundtrip testing functionality
§Usage Example
use senax_pgsql_parser::{connect_to_database, get_database_schema};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool = connect_to_database("postgresql://user:pass@localhost/db").await?;
let schema = get_database_schema(&pool).await?;
println!("Number of tables: {}", schema.tables.len());
for table in &schema.tables {
println!("Table: {}", table.table_name);
println!("DDL: {}", table.to_ddl());
}
Ok(())
}Structs§
- Check
Constraint - CHECK constraint information
- Column
Info - Column information
- Database
Schema - Complete database schema information
- Foreign
KeyConstraint - Foreign key constraint information
- Geometry
Info - PostGIS geometry detailed information
- Index
Info - Index information
- Table
Info - Table information
Enums§
- Default
Value - Parsed default value types
- Foreign
KeyAction - Foreign key constraint actions
- Geometry
Type - PostGIS geometry types
- Index
Type - Index types
- PostgreSQL
Data Type - PostgreSQL data types
Functions§
- connect_
to_ database - Connect to database
- convert_
mysql_ placeholders_ to_ postgresql - Convert MySQL placeholder (?) to PostgreSQL placeholders ($1, $2, $3, …)
- escape_
db_ identifier - get_
check_ constraints - get_
current_ schema - Get current schema name
- get_
database_ schema - Get complete database schema
- get_
foreign_ key_ constraints - get_
table_ columns - get_
table_ comment - get_
table_ indexes - get_
table_ names - is_
system_ generated_ index - Check if an index is system-generated
- parse_
default_ value - Parse PostgreSQL default value expression