1. Overview
A parser and type checker for SQL written in Haskell. Targets the PostgreSQL dialect of SQL and PL/pgSQL syntax only. BSD licensed.
This is the documentation for version 0.5.x. Documentation for other versions is available here: http://jakewheat.github.io/hssqlppp/.
If you just need a SQL parser, this is an updated project focused on parsing SQL only: http://jakewheat.github.io/simple-sql-parser/latest/.
2. Links
-
Haddock: haddock/index.html
-
Usage examples: examples.html
-
Parsing test cases: ParserTests.html
-
Type-checking test cases: TypeCheckTests.html
-
Quasiquotation test cases: QuasiQuoteTests.html
-
Repository: https://github.com/JakeWheat/hssqlppp
-
Bug tracker: https://github.com/JakeWheat/hssqlppp/issues
-
Changes: https://github.com/JakeWheat/hssqlppp/blob/master/CHANGES
-
Other versions: http://jakewheat.github.io/hssqlppp/
-
Parent project: http://jakewheat.github.io/
-
Contact: jakewheatmail@gmail.com
3. Purpose
Possible uses of this library include:
-
type-checker can help with SQL development and catch bugs which aren’t statically detected by Postgres
-
front end for a SQL DBMS
-
generating SQL code programmatically/ generating SQL from some other source
-
transforming SQL code, possibly using quasiquoting, e.g. writing PL/pgSQL with less boilerplate, or optimisation rewrites
-
viewing the catalog produced by some SQL code
With some extra work:
-
generating documentation for SQL code
-
support running one dialect of SQL on a different DBMS using automatic translation - portable SQL
-
typesafe database access from Haskell
-
lint or semantic analysis for SQL or PL/pgSQL
4. Status
Pre-alpha in the traditional sense (not yet feature complete). Support for parsing SQL solid on a large subset of SQL. Supports queries/DML and DDL. Here is an extract from the parsing tests which gives some examples of what can currently be parsed:
The type checker is currently still being fixed after some reworking of parsing and ast types. It is pretty solid on a wide range of queries.
Extract from the type checking tests:
Currently limited support for quasiquoting, here are the extracts from the tests:
The pretty printer should support everything the parser supports (i.e. it pretty prints code which both the parser and Postgres understand).
Catalog information is limited, supports the type checking. Some information is collected on scalar types, domains, composite types, casts, tables, views and functions.
5. Installation
This project is currently developed on GHC 7.10.2. It has also been tested recently with 7.8.4 and 7.6.3.
To install use
cabal install hssqlppp
To work with the development version:
git clone https://github.com/JakeWheat/hssqlppp.git cd hssqlppp make sandbox make all make test # this will set up a sandbox and build and test the # main packages, hssqlppp, hssqlppp-th and hssqlppp-pg # or make sandbox-devel make really-all # this builds a lot more and takes ages # or you can: cd hssqlppp # wd is now .../hssqlppp/hssqlppp/ cabal install --only-dependencies --enable-tests cabal build cabal test build/dist/Tests/Tests --hide-successes