Specifies the SQL dialect to use.
import { formatDialect, sqlite } from 'sql-formatter';
const result = formatDialect('SELECT * FROM tbl', { dialect: sqlite });
Note: This is part of new API, introduced in version 12.
It can only be used together with the new formatDialect()
function,
not with the old format()
function.
It also can't be used in config file of the command line tool -
for that, use the language option.
The following dialects can be imported from "sql-formatter"
module:
sql
- Standard SQLbigquery
- GCP BigQuerydb2
- IBM DB2hive
- Apache Hivemariadb
- MariaDBmysql
- MySQLn1ql
- Couchbase N1QLplsql
- Oracle PL/SQLpostgresql
- PostgreSQLredshift
- Amazon Redshiftsinglestoredb
- SingleStoreDBsnowflake
- Snowflakespark
- Sparksqlite
- SQLitetransactsql
- SQL Server Transact-SQLtrino
- Trino / Presto
The sql
dialect is meant for cases where you don't know which dialect of SQL you're about to format.
It's not an auto-detection, it just supports a subset of features common enough in many SQL implementations.
This might or might not work for your specific dialect.
Better to always pick something more specific if possible.
The dialect
parameter can also be used to specify a custom SQL dialect configuration:
import { formatDialect, DialectOptions } from 'sql-formatter';
const myDialect: DialectOptions {
tokenizerOptions: {
// See source code for examples of tokenizer config options
// For example: src/languages/sqlite/sqlite.formatter.ts
},
formatOptions: {
// ...
},
};
const result = formatDialect('SELECT * FROM tbl', { dialect: myDialect });
NB! This functionality is experimental and there are no stability guarantees for this API.
The DialectOptions
interface can (and likely will) change in non-major releases.
You likely only want to use this if your other alternative is to fork SQL Formatter.