Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lenra-io/query-parser
https://github.com/lenra-io/query-parser
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lenra-io/query-parser
- Owner: lenra-io
- License: agpl-3.0
- Created: 2022-05-17T15:08:52.000Z (over 2 years ago)
- Default Branch: beta
- Last Pushed: 2023-09-25T13:33:56.000Z (over 1 year ago)
- Last Synced: 2023-09-26T00:07:55.382Z (over 1 year ago)
- Language: Elixir
- Size: 146 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![AGPL License][license-shield]][license-url]
Lenra Query Parser
This repository provides a tool that can parse a JSON query into an AST tree and parse this tree into an Ecto query that can be executed within elixir.
Report Bug
·
Request Feature
## Getting Started
### Prerequisites
You need to add this lib into your phoenix app :
```bash
{:query_parser, git: "https://github.com/lenra-io/query-parser.git", tag: "v1.0.0-beta.X"}
```## Parser
### JSON to AST
With the parser you can parse a JSON query into an AST tree, for more
information about the format of the JSON query consult this [README](). To parse JSON:> $\qquad$ Add the alias:
```
alias QueryParser.AST.Parser
```> $\qquad$ Parse query with function:
```
Parser.from_json(q)
```
$\qquad$ with q the JSON query### AST to Ecto
Once you parse a JSON query into an AST tree you will be able to parse this AST into an Ecto query:> $\qquad$ Add the alias:
```
alias QueryParser.AST.EctoParser
```> $\qquad$ Parse query with function:
```
EctoParser.to_ecto(query, env_id, user_data_id)
```
$\qquad$ with:
$\qquad$ $\qquad$ - query the AST tree
$\qquad$ $\qquad$ - env_id the environement id
$\qquad$ $\qquad$ - user_data_id the id of the user's user datayou can now execute the query with ecto:
```
Repo.all(ecto_query)
Repo.one(ecto_query)
```
with ecto_query the query is parsed before, the all function returns a list of all matching results, the one function returns only one element (beware: if there is more than one result the function returns an error), to learn more about the ecto repository [function](https://hexdocs.pm/ecto/Ecto.Repo.html#query-api)### Two step together:
> $\qquad$ Add the alias:
```
alias QueryParser.AST.{EctoParser, Parser}
```> $\qquad$ Parse query with function:
```
Query
|> Parser.from_json()
|> EctoParser.to_ecto(env_id, user_data_id)
|> Repo.all()
```## Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
If you have a suggestion that would make this better, please open an issue with the tag "enhancement" or "bug".
Don't forget to give the project a star! Thanks again!## License
Distributed under the **AGPL** License. See [LICENSE](./LICENSE) for more information.
## Contact
Lenra - [@lenra_dev](https://twitter.com/lenra_dev) - [email protected]
Project Link: [https://github.com/lenra-io/query-parser](https://github.com/lenra-io/query-parser)
[contributors-shield]: https://img.shields.io/github/contributors/lenra-io/query-parser.svg?style=for-the-badge
[contributors-url]: https://github.com/lenra-io/query-parser/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/lenra-io/query-parser.svg?style=for-the-badge
[forks-url]: https://github.com/lenra-io/query-parser/network/members
[stars-shield]: https://img.shields.io/github/stars/lenra-io/query-parser.svg?style=for-the-badge
[stars-url]: https://github.com/lenra-io/query-parser/stargazers
[issues-shield]: https://img.shields.io/github/issues/lenra-io/query-parser.svg?style=for-the-badge
[issues-url]: https://github.com/lenra-io/query-parser/issues
[license-shield]: https://img.shields.io/github/license/lenra-io/query-parser.svg?style=for-the-badge
[license-url]: https://github.com/lenra-io/query-parser/blob/master/LICENSE