/SQLFluff.jl

Primary LanguageJuliaMIT LicenseMIT

SQLFluff

To install run

]add SQLFluff.jl

This package is a thin wrapper around SQLStrings which adds linting via sqlfluff, so that incorrect SQL should throw an informative error for example

sql"SELET * FROM table "
# ERROR: SQLParseError(Line 1, Position 1: Found unparsable section: 'SELET * FROM mytable')

You can configure a specific dialect with

dialect!("sqlite")

Where the supported dialects are

[
    "ansi",
    "bigquery",
    "db2",
    "exasol",
    "hive",
    "mysql",
    "oracle",
    "postgres",
    "redshift",
    "snowflake",
    "sparksql",
    "sqlite",
    "teradata",
    "tsql",
]

For SQL code that contains interpolated symbols, e.g SELECT * FROM table WHERE x=$x we need to know how to format the data types so the generated SQL can be linted. If your datatype is unsupported you can define

formatter(::Val{:dialect}, ::MyType) = x -> "$x my format"

It should return a function that is capable of correctly formatting your data type. Initial support will go into covering formatting for Postgres and Sqlite.