I needed a way to 'minify' SQL statements in another Crystal project. This turned out to be quite tricky so I figured the easiest way was to create a simple lexer and use the tokens to generate a minified representation. This lexer is also written in Crystal (obviously) 😀.
- Add the dependency to your
shard.yml
:
dependencies:
pg_sql_lexer:
github: horrendo/pg_sql_lexer
- Run
shards install
require "pg_sql_lexer"
:
raw_sql = {slurp from a file maybe}
minified = PgSqlLexer::Formatter.new(PgSqlLexer::Lexer.new(raw_sql).tokens).format_minified
:
You can access the documentation here
- Fork it (https://github.com/horrendo/pg_sql_lexer/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Steve Baldwin - creator and maintainer