sql_formatter 0.1.0 copy "sql_formatter: ^0.1.0" to clipboard
sql_formatter: ^0.1.0 copied to clipboard

A pure-Dart SQL pretty-printer supporting standard SQL, PostgreSQL, MySQL and SQLite dialects. A faithful port of the JS sql-formatter library.

example/main.dart

import 'package:sql_formatter/sql_formatter.dart';

void main() {
  const sql =
      'select id, name, count(*) from users u left join orders o on o.uid=u.id '
      'where u.active=1 and o.total>100 group by id order by name limit 10';

  // Default: standard dialect, UPPER-cased keywords, two-space indent.
  print('--- standard, keywords upper-cased ---');
  print(format(sql));

  // A PostgreSQL-specific query with a `$1` placeholder and a `->>` operator.
  print('\n--- postgresql dialect ---');
  print(format(
    r"select data->>'k' from events where id = $1",
    dialect: SqlDialect.postgresql,
  ));

  // Lower-case the keywords instead of upper-casing them.
  print('\n--- keywords lower-cased ---');
  print(format(
    sql,
    options: const FormatOptions(keywordCase: KeywordCase.lower),
  ));
}
0
likes
160
points
77
downloads

Documentation

API reference

Publisher

verified publisher10v3n4m.cc

Weekly Downloads

A pure-Dart SQL pretty-printer supporting standard SQL, PostgreSQL, MySQL and SQLite dialects. A faithful port of the JS sql-formatter library.

Repository (GitHub)
View/report issues

Topics

#sql #formatting #database #postgresql #parser

License

MIT (license)

More

Packages that depend on sql_formatter