The typedquery package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Base package for parsing queries


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3
Change logNone available
Dependenciesaeson, base (==4.7.*), bytestring, haskell-src-meta, parsec, template-haskell, text, transformers [details]
LicenseBSD3
AuthorMarcin Tolysz
Maintainertolysz@gmail.com
CategoryDatabase
Home pagehttps://github.com/tolysz/typedquery
UploadedFri Dec 19 17:34:55 UTC 2014 by tolysz

Modules

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for typedquery-0.1.0.0

typedquery

Parser for SQL augmented with types

This package provides base parsing facilities for possibly all -simple database packages converting them into -simpel-typed

example: https://github.com/tolysz/sqlite-simple-typed/blob/master/example/src/Main.hs

The basic idea is to start using SQL again, but use comemnts (--) to hide haskell annotation.

This started as QuasiQuotes excercise with the TH inpired printf.

If you do not provide value (or a mean to get on inside query you need to give it outside.

They do the same:

$(genJsonQuery "SET SESSION group_concat_max_len = ? ") conn (10000 :: Int)
$(genJsonQuery "SET SESSION group_concat_max_len = ? -- Int ") conn 10000
$(genJsonQuery "SET SESSION group_concat_max_len = ? -- Int  -- < 1000 ") conn
$(genJsonQuery "SET SESSION group_concat_max_len = ? -- < (1000 :: Int) ") conn

There is a basic syntax, and the base idea is to have a nice easy for eye syntax. It fires the correct execute or query with or without _ depending on the actual SQL syntax

The parser is not complete, I will try to add as many issues there are and try to fix it.

Adnotations start with -- as otherwise HeidiSQL was complaining, then > < ~ or just text.

| syntax | equivalent | ------------------------- | ------------------------------ | bal -- Type | (\v -> v :: Bla) | | bla -- > f | (\v -> f bla ) | | bla -- Type -- > f | (\v -> (f bla):: Type ) | | ? -- Type -- < var | ?? | | ? -- < var | ?? | | ? -- < var | ?? | | ? -- ~ verbatim | ?? |

Eg.

$(genJsonQuery [qq| insert into some_table
  ( timeAsSQLfunction           -- ~ now ()
  , someInputfromAesonViaLens   -- Int  -- < v ^? (key "coolValue" . _Integral) ^. non 3 
  , someUserName                -- Text -- < someNameFromContext
  ) |]) conn

Translates to

execute conn [qq| insert into some_table
      ( timeAsSQLfunction, someInputfromAesonViaLens, someUserName )
      values ( now (), ?, ?) |] 
        [( (v ^? (key "coolValue" . _Integral) ^. non 3 ) :: Int, someNameFromContext Text)]