6 releases
0.1.6 | Jul 18, 2022 |
---|---|
0.1.5 | Jul 17, 2022 |
#2402 in Database interfaces
37KB
996 lines
mongodb-language-model
Parses a MongoDB query and creates an abstract syntax tree (AST) with part of speech tagging. Currently, only strict extended json syntax is supported and not all the cases are being created correctly and some may not be missing altogether.
This library is based on previous Node.js work by Thomas Rueckstiess on the mongodb-language-model repository. It has been ported from Node.js and PEGjs to Rust and pest.rs.
Usage
The module exposes a function parse(query: &str) -> Result<Expression, Error<Rule>>
that takes a mongo JSON query
string and returns the parsed AST structure.
lib.rs
:
mongodb-language-model
is a library for parsing the MongoDB language and
returning an abstract syntax tree using pest.rs.
Example
use mongodb_language_model::*;
let input = r#"{ "$or": [ { "status": "A" }, { "qty": { "$lt": 30 } }] }"#;
let ast = parse(input).unwrap();
Dependencies
~3–4.5MB
~87K SLoC