22 unstable releases (3 breaking)
Uses new Rust 2024
| 0.4.2 | May 7, 2026 |
|---|---|
| 0.4.1 | May 7, 2026 |
| 0.3.0 | May 7, 2026 |
| 0.2.6 | May 4, 2026 |
| 0.1.4 | Feb 26, 2026 |
#2 in #parser-and-formatter
78 downloads per month
Used in thyme-sql
24KB
564 lines
Poppy-sql
Very fast parser and formatter for standalone and embedded SQL
Dialect support
Explicit support for:
- PostgreSQL
- MySQL
- SQLite
Generic SQL dialect supported.
What is this for?
Raw SQL doesn't only live in SQL files, it's often embedded in application code.
Poppy-sql is useful for:
- Finding all of the queries in a directory to return them as a parsed SQL result to be consumed as a library.
- Formatting all of the queries found in a directory with an easy to manage configuration as a binary.
How to use?
As a formatter (binary)
Poppy-sql is available to install through cargo using: cargo install poppy-sql
Run poppy-sql in a directory with the files you want formatted in it, poppy-sql '{target_file}' to format a specific file, or poppy-sql '{target_file1} {target_file2}' to format multiple files.
You can ignore queries on a per-query basis by adding a comment anywhere in the query like: -- poppy-ignore
It can be integrated into your .pre-commit-config.yaml like:
repos:
- repo: https://github.com/starflower-sh/poppy-sql
rev: v0.4.0
hooks:
- id: poppy-sql
You can set configuration by creating a .poppy.toml file.
Reference the default.poppy.toml file for the expected configuration format.
The default file will be used to populate values that aren't specified in your .poppy.toml.
Poppy-sql will reference the nearest ancestor config file at or below the directory the format command is run, so you can have different config files apply in the same run of poppy-sql.
Note: Formatting will not run against filetypes not specified in the config even if directly targeted.
As a parser (library)
Poppy-sql is also available as a library for your rust projects where you can parse files using the parsing modules.
What file types are supported?
Currently: ["sql", "py", "rs", "ts", "js", "mjs", "vue"]
Other file types will be ignored if Poppy-sql is run in the containing folder, or print an error message if specifically targeted.
Dotfiles and some misc directories are skipped (like node_modules), exact matches can be found in the constants module.
Is it ready to use?
Poppy-sql is in active development, but you should be able to use its latest releases with a touch of caution.
Be aware that Poppy-sql follows semantic versioning to represent backwards incompatible changes and always double check the formatted results.
Dependencies
~5.5–8MB
~167K SLoC