Giter VIP home page Giter VIP logo

pg-formatter-ts's Introduction

pg-formatter-ts npm Coverage Status

pg-formatter-ts logo

pg-formatter-ts is a TypeScript library that wraps the pgFormatter CLI tool for formatting PostgreSQL SQL code.
With a simple and easy-to-use API, it provides the ability to format SQL code programmatically with various formatting options.

Compared to the existing pg-formatter library, pg-formatter-ts offers improved TypeScript support and better integration with modern TypeScript/JavaScript projects. This library utilizes the same underlying CLI tool, but provides a more streamlined and developer-friendly API. Additionally, pg-formatter-ts supports all available CLI options of pgFormatter, allowing for greater customization and control over the formatting process.

Installation

yarn install pg-formatter-ts

Prerequisites

Ensure that perl is installed on your system, as pgFormatter relies on it. You can check if Perl is installed by running perl -v in your command line. If it's not installed, please visit the Perl official website for installation instructions.

Usage

import { format, PgFormatOptions } from "pg-formatter-ts";

const sqlCode = "SELECT id, name, age FROM users WHERE age >= 18;";
const options: PgFormatOptions = {
    keywordCase: 2,
    spaces: 2,
};

format(sqlCode, options).then((formattedCode) => {
    console.log(formattedCode);
});

Options

pg-formatter-ts accepts an optional PgFormatOptions object as a parameter for the format function. The options available are:

interface PgFormatOptions {
    anonymize?: boolean;
    commaStart?: boolean;
    commaBreak?: boolean;
    config?: string;
    wrapComment?: boolean;
    debug?: boolean;
    commaEnd?: boolean;
    functionCase?: number;
    format?: string;
    nogrouping?: boolean;
    help?: boolean;
    inplace?: boolean;
    keepNewline?: boolean;
    noExtraLine?: boolean;
    maxlength?: number;
    multiline?: boolean;
    nocomment?: boolean;
    numbering?: boolean;
    output?: string;
    placeholder?: string;
    redshift?: boolean;
    spaces?: number;
    separator?: string;
    formatType?: boolean;
    tabs?: boolean;
    keywordCase?: number;
    typeCase?: number;
    version?: boolean;
    wrapLimit?: number;
    wrapAfter?: number;
    noRcfile?: boolean;
    extraFunction?: string;
    extraKeyword?: string;
    noSpaceFunction?: boolean;
}

For a detailed explanation of each option, refer to the pgFormatter documentation.

Disclaimer

The code for this library and this README were generated by an AI called GPT-4, developed by OpenAI. While GPT-4 strives for accuracy, it is possible that the code and documentation may contain errors or inconsistencies. Please feel free to report any issues or submit pull requests with improvements, as your contributions are welcome and appreciated.

License

This project is licensed under the MIT License.

pg-formatter-ts's People

Contributors

nightvisi0n avatar

Stargazers

 avatar

Watchers

 avatar  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.