GithubHelp home page GithubHelp logo

manticore-projects / jsqlformatter Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 5.0 5.86 MB

Java SQL Formatter, Beautifier and Pretty Printer

Home Page: https://manticore-projects.com/JSQLFormatter/index.html

License: Other

Java 25.16% PLSQL 12.96% Python 0.24% ANTLR 3.06% HTML 0.47% CSS 24.84% JavaScript 1.46% XSLT 0.27% TSQL 0.78% PLpgSQL 30.77%
beautify formatter java mssql mysql oracle postgres pretty-print sql

jsqlformatter's Introduction

manticore JSQLFormatter

Java SQL Formatter, Beautifier and Pretty Printer. Please visit our Website and try the ONLINE Demo.

Gradle CI Maven Codacy Badge Coverage Status License issues - JSQLFormatter PRs Welcome

ANSI Output

Features

  • Based on JSQLParser

  • Supports complex SELECT, INSERT INTO, MERGE, UPDATE, DELETE, CREATE, ALTER statements

  • RDBMS agnostic and compatible to

  • ANSI syntax highlighting

  • Formatting Options for Indent Width, Comma Before or After, Upper/Lower/Camel Case spelling

  • Import from Java String or StringBuilder, while preserving variables

  • Export to Java String, StringBuilder or MessageFormat, while handling parameters

  • Command Line Option (CLI) and SQL Inline Options

    java -jar JSQLFormatter.jar [-i <arg>] [-o <arg>] [-f <arg> |
           --ansi | --html]   [-t <arg> | -2 | -8]   [--keywordSpelling <arg>]
           [--functionSpelling <arg>] [--objectSpelling <arg>] [--separation
           <arg>] [--squareBracketQuotation <arg>]
    
     -i,--inputFile <arg>               The input SQL file or folder.
     -o,--outputFile <arg>              The out SQL file for the formatted
                        statements.
     -f,--outputFormat <arg>            The output-format.
                        [PLAIN* ANSI HTML RTF]
        --ansi                          Output ANSI annotated text.
        --html                          Output HTML annotated text.
     -t,--indent <arg>                  The indent width.
                        [2 4* 8]
     -2                                 Indent with 2 characters.
     -8                                 Indent with 8 characters.
        --keywordSpelling <arg>         Keyword spelling.
                        [UPPER*, LOWER, CAMEL, KEEP]
        --functionSpelling <arg>        Function name spelling.
                        [UPPER, LOWER, CAMEL*, KEEP]
        --objectSpelling <arg>          Object name spelling.
                        [UPPER, LOWER*, CAMEL, KEEP]
        --separation <arg>              Position of the field separator.
                        [BEFORE*, AFTER]
        --squareBracketQuotation <arg>  Position of the field separator.
                        [AUTO*, YES, NO]
  • simple usage of the Java library

    import com.manticore.jsqlformatter.JSqlFormatter;
    ...
    String formattedSql = JSqlFormatter.format("SELECT * FROM table1")

    with Maven Artifact:

    <dependency>
        <groupId>com.manticore-projects.jsqlformatter</groupId>
        <artifactId>jsqlformatter</artifactId>
        <version>4.8.0</version>
    </dependency>

Samples

Inline Formatting Options

-- @JSQLFormatter(indentWidth=8, keywordSpelling=UPPER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE)
UPDATE cfe.calendar
SET     year_offset = ?                    /* year offset */
        , settlement_shift = To_Char( ? )  /* settlement shift */
        , friday_is_holiday = ?            /* friday is a holiday */
        , saturday_is_holiday = ?          /* saturday is a holiday */
        , sunday_is_holiday = ?            /* sunday is a holiday */
WHERE id_calendar = ?
;

-- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER)
update CFE.CALENDAR
set YEAR_OFFSET = ?                    /* year offset */,
    SETTLEMENT_SHIFT = to_char( ? )    /* settlement shift */,
    FRIDAY_IS_HOLIDAY = ?              /* friday is a holiday */,
    SATURDAY_IS_HOLIDAY = ?            /* saturday is a holiday */,
    SUNDAY_IS_HOLIDAY = ?              /* sunday is a holiday */
where ID_CALENDAR = ?
;

Complex Comments

-- UPDATE CALENDAR
UPDATE cfe.calendar
SET year_offset = ?            /* year offset */
    , settlement_shift = ?     /* settlement shift */
    , friday_is_holiday = ?    /* friday is a holiday */
    , saturday_is_holiday = ?  /* saturday is a holiday */
    , sunday_is_holiday = ?    /* sunday is a holiday */
WHERE id_calendar = ?
;

-- BOTH CLAUSES PRESENT 'with a string' AND "a field"
MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a
    USING all_objects      /*the source table*/
        ON ( /*joins in()!*/ a.object_id = b.object_id )
-- INSERT CLAUSE
WHEN /*comments between keywords!*/ NOT MATCHED THEN
    INSERT ( object_id     /*ID Column*/
                , status   /*Status Column*/ )
    VALUES ( b.object_id
                , b.status )
/* UPDATE CLAUSE
WITH A WHERE CONDITION */
WHEN MATCHED THEN          /* Lets rock */
    UPDATE SET  a.status = '/*this is no comment!*/ and -- this ain''t either'
    WHERE   b."--status" != 'VALID'
;

More Samples

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.