Skip to main content

Crate senax_pgsql_parser

Crate senax_pgsql_parser 

Source
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§

CheckConstraint
CHECK constraint information
ColumnInfo
Column information
DatabaseSchema
Complete database schema information
ForeignKeyConstraint
Foreign key constraint information
GeometryInfo
PostGIS geometry detailed information
IndexInfo
Index information
TableInfo
Table information

Enums§

DefaultValue
Parsed default value types
ForeignKeyAction
Foreign key constraint actions
GeometryType
PostGIS geometry types
IndexType
Index types
PostgreSQLDataType
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