Library for SQL parsing, AST manipulation and SQL generation in F#
F# Other
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
.paket
docs
examples
lib
src/FsSqlDom
tests/FsSqlDom.Tests
.gitattributes
.gitignore
.travis.yml
FsSqlDom.sln
LICENSE.txt
README.md
RELEASE_NOTES.md
appveyor.yml
build.cmd
build.fsx
build.sh
paket.dependencies
paket.lock

README.md

FsSqlDom

A library to work with SQL syntax trees in F#. Can be used for:

  • Analyzing queries
    • Finding performance problems
    • Checking permissions
  • Rewriting queries
    • Optimize poorly written queries
    • Add/remove conditions to WHERE clause for security, etc
  • Generating scripts from modified SQL syntax trees

It covers 100% of TSQL, because it leverages the existing TransactSql.ScriptDom C# library from Microsoft, and is able to convert losslessly* back and forth between Microsofts C# type hierarchy, and a new set of discriminated unions in F#.

* Stream token positions excluded

Check out the intro blog post for an example of the first two. For script generation, you could check out the tests

Installation

Install from nuget:

Install-Package FsSqlDom

Gallery WPF App

The main output of this project is a class library, but it also has a windows application with some examples and tools to help use the library (and the C# library from Microsoft).

Features:

  • Basic usage
  • Syntax Builder (similar to Roslyn Quoter
  • Table Relationships vizualizer (based on analysing AST of views, procedures, and functions)

Screenshots:

UI

Syntax Builder

Design questions

  • Q: Why generate only discriminated unions (DUs) with many fields, instead of DUs with a single record value?
    • A: In this case, it would result it way too many types, which creates a compiler (and tooling) performance problem.