url parameter parser for rest filter inquiry

Related tags

Parsing inquerest
Overview

inquerest

Inquerest can parse complex url query into a SQL abstract syntax tree.

Example this url:

 /person?age=lt.42&(student=eq.true|gender=eq.'M')&group_by=sum(age),grade,gender&having=min(age)=gt.42&order_by=age.desc,height.asc&page=20&page_size=100

will be parsed into:

Select {
        from_table: FromTable {
            from: Table {
                name: "person",
            },
            join: None,
        },
        filter: Some(
            BinaryOperation(
                BinaryOperation {
                    left: BinaryOperation(
                        BinaryOperation {
                            left: Column(
                                Column {
                                    name: "age",
                                },
                            ),
                            operator: Lt,
                            right: Value(
                                Number(
                                    42.0,
                                ),
                            ),
                        },
                    ),
                    operator: And,
                    right: Nested(
                        BinaryOperation(
                            BinaryOperation {
                                left: BinaryOperation(
                                    BinaryOperation {
                                        left: Column(
                                            Column {
                                                name: "student",
                                            },
                                        ),
                                        operator: Eq,
                                        right: Value(
                                            Bool(
                                                true,
                                            ),
                                        ),
                                    },
                                ),
                                operator: Or,
                                right: BinaryOperation(
                                    BinaryOperation {
                                        left: Column(
                                            Column {
                                                name: "gender",
                                            },
                                        ),
                                        operator: Eq,
                                        right: Value(
                                            String(
                                                "M",
                                            ),
                                        ),
                                    },
                                ),
                            },
                        ),
                    ),
                },
            ),
        ),
        group_by: Some(
            [
                Function(
                    Function {
                        name: "sum",
                        params: [
                            Column(
                                Column {
                                    name: "age",
                                },
                            ),
                        ],
                    },
                ),
                Column(
                    Column {
                        name: "grade",
                    },
                ),
                Column(
                    Column {
                        name: "gender",
                    },
                ),
            ],
        ),
        having: Some(
            BinaryOperation(
                BinaryOperation {
                    left: Function(
                        Function {
                            name: "min",
                            params: [
                                Column(
                                    Column {
                                        name: "age",
                                    },
                                ),
                            ],
                        },
                    ),
                    operator: Gt,
                    right: Value(
                        Number(
                            42.0,
                        ),
                    ),
                },
            ),
        ),
        projection: None,
        order_by: Some(
            [
                Order {
                    expr: Column(
                        Column {
                            name: "age",
                        },
                    ),
                    direction: Some(
                        Desc,
                    ),
                },
                Order {
                    expr: Column(
                        Column {
                            name: "height",
                        },
                    ),
                    direction: Some(
                        Asc,
                    ),
                },
            ],
        ),
        range: Some(
            Page(
                Page {
                    page: 20,
                    page_size: 100,
                },
            ),
        ),
    }

Which translate to the sql statement:

SELECT * FROM person WHERE age < 42 AND (student = true OR gender = 'M') GROUP BY sum(age), grade, gender HAVING min(age) > 42 ORDER BY age DESC, height ASC LIMIT 100 OFFSET 1900 ROWS

Note: However, you don't want to convert to the sql statement directly to avoid sql injection attack. You need to validate the tables and columns if it is allowed to be accessed by the user. You also need to extract the values yourself and supply it as a parameterized value into your ORM.

Please support this project:

Become a patron

License: MIT

You might also like...
A fast, extensible, command-line arguments parser

parkour A fast, extensible, command-line arguments parser. Introduction 📚 The most popular argument parser, clap, allows you list all the possible ar

Soon to be AsciiDoc parser implemented in rust!

pagliascii "But ASCII Doc, I am Pagliascii" Soon to be AsciiDoc parser implemented in rust! This project is the current implementation of the requeste

An LR parser generator, implemented as a proc macro

parsegen parsegen is an LR parser generator, similar to happy, ocamlyacc, and lalrpop. It currently generates canonical LR(1) parsers, but LALR(1) and

A rusty, dual-wielding Quake and Half-Life texture WAD parser.

Ogre   A rusty, dual-wielding Quake and Half-Life texture WAD parser ogre is a rust representation and nom parser for Quake and Half-Life WAD files. I

A modern dialogue executor and tree parser using YAML.

A modern dialogue executor and tree parser using YAML. This crate is for building(ex), importing/exporting(ex), and walking(ex) dialogue trees. convo

A friendly parser combinator crate

Chumsky A friendly parser combinator crate that makes writing LL-1 parsers with error recovery easy. Example Here follows a Brainfuck parser. See exam

Minimalist pedantic command line parser

Lexopt Lexopt is an argument parser for Rust. It tries to have the simplest possible design that's still correct. It's so simple that it's a bit tedio

Universal configuration library parser

LIBUCL Table of Contents generated with DocToc Introduction Basic structure Improvements to the json notation General syntax sugar Automatic arrays cr

PEG parser for YAML written in Rust 🦀

yaml-peg PEG parser (pest) for YAML written in Rust 🦀 Quick Start ⚡️ # Run cargo run -- --file example_files/test.yaml # Output { "xmas": "true",

Comments
  • PostgREST

    PostgREST

    This is an interesting project; have you come across PostgREST?

    Looks like theremight be some similarity in the param syntax

    (feel free to close this after reading by the way, it's not really an issue)

    opened by cpursley 1
  • convert doc comment to regular comment

    convert doc comment to regular comment

    rust-lang/rust#57882 is modifying the unused_doc_comments lint to fire on mistakenly documented macro expansions. A crater run detected that this crate will break due to this change, likely because of the use of deny(unused_doc_comments) or deny(warnings).

    While this kind of breakage is allowed under Rust's stability guarantees, I am opening PRs to affected crates to reduce the impact.

    This PR protects your crate from future breakage by converting the offending doc comment to a regular comment.


    This change is Reviewable

    opened by euclio 0
Releases(0.0.9)
Owner
Jovansonlee Cesar
I'm for hire. If your company uses rust and interested in one of my projects, please recommend me.
Jovansonlee Cesar
Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Microformats 5 Jul 19, 2022
A native Rust port of Google's robots.txt parser and matcher C++ library.

robotstxt A native Rust port of Google's robots.txt parser and matcher C++ library. Native Rust port, no third-part crate dependency Zero unsafe code

Folyd 72 Dec 11, 2022
Rust parser combinator framework

nom, eating data byte by byte nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromi

Geoffroy Couprie 7.6k Jan 7, 2023
Parsing Expression Grammar (PEG) parser generator for Rust

Parsing Expression Grammars in Rust Documentation | Release Notes rust-peg is a simple yet flexible parser generator that makes it easy to write robus

Kevin Mehall 1.2k Dec 30, 2022
A fast monadic-style parser combinator designed to work on stable Rust.

Chomp Chomp is a fast monadic-style parser combinator library designed to work on stable Rust. It was written as the culmination of the experiments de

Martin Wernstål 228 Oct 31, 2022
A parser combinator library for Rust

combine An implementation of parser combinators for Rust, inspired by the Haskell library Parsec. As in Parsec the parsers are LL(1) by default but th

Markus Westerlind 1.1k Dec 28, 2022
LR(1) parser generator for Rust

LALRPOP LALRPOP is a Rust parser generator framework with usability as its primary goal. You should be able to write compact, DRY, readable grammars.

null 2.4k Jan 7, 2023
The Elegant Parser

pest. The Elegant Parser pest is a general purpose parser written in Rust with a focus on accessibility, correctness, and performance. It uses parsing

pest 3.5k Jan 8, 2023
A typed parser generator embedded in Rust code for Parsing Expression Grammars

Oak Compiled on the nightly channel of Rust. Use rustup for managing compiler channels. You can download and set up the exact same version of the comp

Pierre Talbot 138 Nov 25, 2022
Rust query string parser with nesting support

What is Queryst? This is a fork of the original, with serde and serde_json updated to 0.9 A query string parsing library for Rust inspired by https://

Stanislav Panferov 67 Nov 16, 2022