Skip to content

derui/ocaml-sql-format

Repository files navigation

SQL formatter built by OCaml

This tool is a simple formatter for SQL.

The currently supported SQL syntax is minimum that maintainers use on a daily basis.

Plans

  • [ ] Support various syntax
  • [ ] Support RDBMS-specific dialects

Usage

# print formatted SQL in <file.sql> to stdout
$ ocaml-sql-format file.sql

# You can redirect to other file
$ ocaml-sql-format file.sql > other.sql

# Can pass multiple files as arguments
$ ocaml-sql-format file1.sql file2.sql

# In-place update
$ ocaml-sql-format -w file.sql
$ ocaml-sql-format --write file.sql

# Specify configuration
$ ocaml-sql-format -c <config file> file.sql

Configuration

Users can change some behaviors by configuration file. Format of configuration file is toml. Configuration file content is below.

[settings]

# format SQL keywords to UPPERCASE or lowercase
# Default value is `upper`
keyword = "lower"               # lowercase
keyword = "upper"               # UPPERCASE

# Size of indentation that is used to some statement, such as select, update, or some expressions.
# Default value is 4
indent_size = 2

# Maximum line length to detect wrap expression.
# Default value is 100
max_line_length = 80

Development

This repository uses Task to manage some development tasks. But if you do not install Task, you can use dune directly.

Requirements

  • dune
  • opam
  • Task (optional)

Commands

# build executable
$ task build

# bulid tools for development
$ task build-tool

# run teest
$ task test

# promote result into expectation tests
$ task promote

Generators

Generator for keyword

Keyword generation for sedlex.

task keyword KEYWORD=<keyword>

Generator for syntax

Syntax generation. This command generates OCaml sources for Cst/Printer/Parser

$ task new-ast -- "syntax name"

LICENSE

MIT

About

A SQL Formatter built with Pure OCaml

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages