GithubHelp home page GithubHelp logo

isabella232 / sql-format Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apla/sql-format

0.0 0.0 0.0 485 KB

A whitespace formatter for different query languages

Home Page: https://zeroturnaround.github.io/sql-formatter/

License: MIT License

HTML 4.45% JavaScript 95.55%

sql-format's Introduction

SQL Formatter NPM version Build Status Coverage Status

SQL Formatter is a JavaScript library for pretty-printing SQL queries. It started as a port of a PHP Library, but has since considerably diverged. It supports Standard SQL, Couchbase N1QL, IBM DB2 and Oracle PL/SQL dialects.

โ†’ Try the demo.

Install

Get the latest version from NPM:

npm install --save sql-formatter

Usage

import sqlFormatter from "sql-formatter";

console.log(sqlFormatter.format("SELECT * FROM table1"));

This will output:

SELECT
  *
FROM
  table1

You can also pass in configuration options:

sqlFormatter.format("SELECT *", {
    language: "n1ql", // Defaults to "sql"
    indent: "    "   // Defaults to two spaces
});

Currently just four SQL dialects are supported:

Placeholders replacement

// Named placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", {
    params: {foo: "'bar'"}
}));

// Indexed placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", {
    params: ["'bar'"]
}));

Both result in:

SELECT
  *
FROM
  tbl
WHERE
  foo = 'bar'

Usage without NPM

If you don't use a module bundler, clone the repository, run npm install and grab a file from /dist directory to use inside a <script> tag. This makes SQL Formatter available as a global variable window.sqlFormatter.

Contributing

# run linter and tests
$ npm run check

...and you're ready to poke us with a pull request.

License

MIT

sql-format's People

Contributors

nene avatar ukupat avatar mtxr avatar rahelest avatar mathsalmi avatar apla avatar osv avatar olsender avatar bsideup avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.