github sql-formatter-org/sql-formatter v12.0.0
12.0.0

latest releases: v15.4.9, v15.4.8, v15.4.7...
2 years ago

Major formatting style change

Most of the simple statements are now formatted more on one line (#483).

For example the following SQL, previously formatted as follows:

ALTER TABLE
  foo
ALTER COLUMN
  col1
SET DEFAULT
  10;

DROP TABLE
  my_tbl;

DELETE FROM
  customers
WHERE
  age > 99;

UPDATE
  orders
SET
  price = 0,
  total = 0
WHERE
  deleted = TRUE;

will now be formatted on a single line:

ALTER TABLE foo
ALTER COLUMN col1
SET DEFAULT 10;

DROP TABLE my_tbl;

DELETE FROM customers
WHERE
  age > 99;

UPDATE orders
SET
  price = 0,
  total = 0
WHERE
  deleted = TRUE;

New API for smaller bundle size

When using the format() function, all the dialects need to be loaded because the actual dialect is determined at runtime. Which means a bundler like Webpack will need to bundle up code of all the dialects even when just a single one is needed. This will be something like 4x overhead compared to bundling just a single dialect.

There's now a new API which enables tree-shaking to eliminate the code of unused dialects:

import { formatDialect, sqlite } from "sql-formatter";

formatDialect("SELECT * FROM tbl", { dialect: sqlite });

See the docs for details.

Related issues/PRs: #511 #515 #452

Breaking changes in extension API

The above change also breaks the current extension API. Notably the language parameter no more works for specifying a custom dialect. Instead use the new formatDialect() API for the same purpose.

Also, instead of extending the Formatter class, there's now a DialectOptions object (#493). So one no more needs to extend a class, but can simply provide a config object.

Other new features

  • Support for custom quote types (in custom dialect config) #516 #503

Bugfixes

  • Support named function arguments in Trino with => operator #510
  • Add package.json to list of exports #499
  • Support nested CASE expressions #494
  • The MySQL USE keyword formatting should no more cause syntax error #456

Don't miss a new sql-formatter release

NewReleases is sending notifications on new releases.