Expand description
§PostgREST Query Parser
A high-performance Rust library for parsing PostgREST query strings into structured SQL queries.
§Features
- Complete PostgREST API Support: All 22+ filter operators (eq, neq, gt, gte, lt, lte, like, ilike, match, imatch, in, is, fts, plfts, phfts, wfts, cs, cd, ov, sl, sr, nxl, nxr, adj)
- Logic Operators: AND, OR, NOT with arbitrary nesting
- JSON Path Navigation:
->and->>operators for JSONB fields - Type Casting: Cast fields with
::typesyntax - Full-Text Search: Multiple FTS operators with language support
- Quantifiers:
anyandallquantifiers for array comparisons - Array/Range Operators: PostgreSQL array and range type support
- Ordering: Multi-column ordering with nulls handling
- Pagination:
limitandoffsetsupport - SQL Generation: Convert parsed queries to parameterized PostgreSQL SQL
§Quick Start
use postgrest_parser::{parse_query_string, query_string_to_sql};
// Parse a PostgREST query string
let query = "select=id,name,email&age=gte.18&status=in.(active,pending)&order=created_at.desc&limit=10";
let params = parse_query_string(query).unwrap();
assert!(params.has_select());
assert!(params.has_filters());
assert_eq!(params.limit, Some(10));
// Convert to SQL
let result = query_string_to_sql("users", query).unwrap();
println!("SQL: {}", result.query);
println!("Params: {:?}", result.params);§Filter Operators
§Comparison Operators
eq- Equal toneq- Not equal togt- Greater thangte- Greater than or equal tolt- Less thanlte- Less than or equal to
§Pattern Matching
like- SQL LIKE pattern matchingilike- Case-insensitive LIKEmatch- POSIX regex matchimatch- Case-insensitive regex match
§Array Operators
in- Value in listcs- Contains (array/range)cd- Contained in (array/range)ov- Overlaps (array)
§Full-Text Search
fts- Full-text search using plainto_tsqueryplfts- Plain full-text search (alias for fts)phfts- Phrase full-text search using phraseto_tsquerywfts- Websearch full-text search using websearch_to_tsquery
§Range Operators
sl- Strictly left ofsr- Strictly right ofnxl- Does not extend to right ofnxr- Does not extend to left ofadj- Adjacent to
§Special Operators
is- IS NULL, IS TRUE, IS FALSE, etc.
§Examples
§Simple Filtering
use postgrest_parser::parse_query_string;
let query = "age=gte.18&status=eq.active";
let params = parse_query_string(query).unwrap();
assert_eq!(params.filters.len(), 2);§Logic Operators
use postgrest_parser::parse_query_string;
let query = "and=(age.gte.18,status.eq.active)";
let params = parse_query_string(query).unwrap();
assert!(params.has_filters());§JSON Path Navigation
use postgrest_parser::parse_query_string;
let query = "data->name=eq.John&data->>email=like.*@example.com";
let params = parse_query_string(query).unwrap();
assert_eq!(params.filters.len(), 2);§Full-Text Search
use postgrest_parser::parse_query_string;
let query = "content=fts(english).search term";
let params = parse_query_string(query).unwrap();§Quantifiers
use postgrest_parser::parse_query_string;
let query = "tags=eq(any).{rust,elixir}";
let params = parse_query_string(query).unwrap();Re-exports§
pub use ast::Cardinality;pub use ast::Column;pub use ast::ConflictAction;pub use ast::Count;pub use ast::DeleteParams;pub use ast::Direction;pub use ast::Field;pub use ast::Filter;pub use ast::FilterOperator;pub use ast::FilterValue;pub use ast::InsertParams;pub use ast::InsertValues;pub use ast::ItemHint;pub use ast::ItemType;pub use ast::JsonOp;pub use ast::Junction;pub use ast::LogicCondition;pub use ast::LogicOperator;pub use ast::LogicTree;pub use ast::Missing;pub use ast::Nulls;pub use ast::OnConflict;pub use ast::Operation;pub use ast::OrderTerm;pub use ast::ParsedParams;pub use ast::Plurality;pub use ast::PreferOptions;pub use ast::Quantifier;pub use ast::Relationship;pub use ast::Resolution;pub use ast::ResolvedTable;pub use ast::ReturnRepresentation;pub use ast::RpcParams;pub use ast::SelectItem;pub use ast::Table;pub use ast::UpdateParams;pub use error::Error;pub use error::ParseError;pub use error::SqlError;pub use parser::field;pub use parser::get_profile_header;pub use parser::identifier;pub use parser::json_path;pub use parser::json_path_segment;pub use parser::logic_key;pub use parser::parse_delete_params;pub use parser::parse_filter;pub use parser::parse_insert_params;pub use parser::parse_json_body;pub use parser::parse_logic;pub use parser::parse_order;pub use parser::parse_order_term;pub use parser::parse_prefer_header;pub use parser::parse_qualified_table;pub use parser::parse_rpc_params;pub use parser::parse_select;pub use parser::parse_update_params;pub use parser::reserved_key;pub use parser::resolve_schema;pub use parser::type_cast;pub use parser::validate_insert_body;pub use parser::validate_update_body;pub use sql::QueryBuilder;pub use sql::QueryResult;
Modules§
Structs§
- Filter
Clause Result - Result of building a filter clause.
Functions§
- build_
filter_ clause - Builds a WHERE clause from filter conditions without the full query.
- operation_
to_ sql - Converts an Operation to SQL
- parse
- Unified parse function for all PostgREST operations
- parse_
params - Parses query parameters from a HashMap into structured parameters.
- parse_
params_ from_ pairs - parse_
query_ string - Parses a PostgREST query string into structured parameters.
- query_
string_ to_ sql - Parses a PostgREST query string and converts it directly to SQL.
- to_sql
- Converts parsed parameters into a parameterized PostgreSQL SELECT query.