Crate pg_parse

Source
Expand description

§pg_parse

PostgreSQL parser that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.

Warning! This library is in early stages of development so any APIs exposed are subject to change.

§Getting started

Add the following to your Cargo.toml

[dependencies]
pg_parse = "0.9"

§Example: Parsing a query

use pg_parse::ast::Node;

let result = pg_parse::parse("SELECT * FROM contacts");
assert!(result.is_ok());
let result = result.unwrap();
assert!(matches!(*&result[0], Node::SelectStmt(_)));

// We can also convert back to a string, if the `str` feature is enabled (enabled by default).
#[cfg(feature = "str")]
assert_eq!(result[0].to_string(), "SELECT * FROM contacts");

Modules§

ast
Generated structures representing the PostgreSQL AST.

Structs§

Fingerprint
Represents the resulting fingerprint containing both the raw integer form as well as the corresponding 16 character hex value.

Enums§

Error
Error structure representing the basic error scenarios for pg_parse.

Functions§

fingerprint
Fingerprints the given SQL statement. Useful for comparing parse trees across different implementations of libpg_query.
normalize
Normalizes the given SQL statement, returning a parameterized version.
parse
Parses the given SQL statement into the given abstract syntax tree.
parse_debug
Similar to parse: parses the given SQL statement into the given abstract syntax tree but also returns the raw output generated by the postgres parser.
parse_plpgsql
An experimental API which parses a PLPGSQL function. This currently returns the raw JSON structure.

Type Aliases§

Result
Convenient Result alias for returning pg_parse::Error.