Giter Site home page Giter Site logo

bungeemonkee / poormanstsqlformatterredux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taok/poormanstsqlformatter

3.0 1.0 1.0 2.44 MB

This is a port of Poor Man's T-SQL Formatter to .Net Standard 1.4 so it can be used with .Net or .Net Core. Everything but the core library (console app, web app, plugins, etc.) has been removed.

License: GNU Affero General Public License v3.0

C# 100.00%

poormanstsqlformatterredux's Introduction

Poor Man's T-SQL Formatter Redux

This is a port of Poor Man's T-SQL Formatter to .Net Standard 1.4 so it can be used with .Net or .Net Core. Everything but the core library (console app, web app, plugins, etc.) has been removed.

Features

  • Simple Xml-based parse tree
  • Extensible, with possibility of supporting other SQL dialects (but none implemented)
  • Configurable according to SQL formatting preferences
  • Handles "procedural" T-SQL; this is not just a SQL statement formatter, but it also formats entire batches, and multi-batch scripts.
  • Fault-tolerant parsing and formatting - if some unknown SQL construct is encountered or a keyword is misinterpreted, parsing does not fail (but will simply not colorize or indent that portion correctly). If the parsing fails more catastrophically, a "best effort" will be made and warning displayed (or in the case of interactive use, eg in SSMS, the operation can be aborted).
  • Reasonably fast: reformatting 1,500 or so files totalling 4MB takes 30 seconds on a cheap atom-processor (2009) netbook.

General Limitations

  • This is NOT a full SQL-parsing solution: only "coarse" parsing is performed, the minimum necessary for re-formatting.
  • The standard formatter does not always maintain the order of comments in the code; a comment inside an "INNER JOIN" compound keyword, like "inner/*test*/join", would get moved out, to "INNER JOIN /*test*/". The original data is maintaned in the parse tree, but the standard formatter shuffles comments in cases like this for clarity.
  • DDL parsing, in particular, is VERY coarse - the bare minimum to display ordered table column and procedure parameter declarations.
  • No effort has been made to support compatibility level 70 (SQL Server 7)
  • Where there is ambiguity between different compatibility levels (eg cross apply parens in compatibility level 90 vs table hints without "WITH" keyword in compatibility level 80), no approach has been decided. For now, table hints without WITH are considered to be arguments to a function.

Known Issues / Todo

  • Handling of DDL Triggers (eg "FOR LOGON")
  • Formatting/indenting of ranking functions
  • FxCop checking
  • And other stuff that is tracked in the GitHub issues list

Version Numbering

Each version will have two numbers: a Windows file version and a SemVer version. The SemVer version will be derived from the Windows file version.

Versioning will follow this pattern:

  • Major Version : Increased when there is a release that breaks a public api
  • Minor Version : Increased for each non-api-breaking release
  • Build Number : 0 for alpha versions, 1 for beta versions, 2 for release candidates, 3 for releases
  • Revision : Always 0 for release versions, always 1+ for alpha, beta, rc versions to indicate the alpha/beta/rc number (alpha/beeta/rc numbers should always be two-digits)

So the following versions are equalivalent

  • 1.0.0.1 => 1.0.0-alpha01
  • 1.0.1.1 => 1.0.1-beta01
  • 1.0.2.1 => 1.0.2-rc01
  • 1.0.3.0 => 1.0.3

License & Credits

This application and library is released under the GNU Affero GPL v3: http://www.gnu.org/licenses/agpl.txt

Thanks to Tao Klerks who wrote the original (seemingly now defunct) Poor Man's T-SQL Formatter and anyone who contributed to that project.

poormanstsqlformatterredux's People

Contributors

taok avatar timothyk avatar bungeemonkee avatar

Stargazers

 avatar  avatar Cezary Piątek avatar

Watchers

 avatar

Forkers

mschechner

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.