typedquery: Parser for SQL augmented with types

[ bsd3, database, library ] [ Propose Tags ] [ Report a vulnerability ]

Base package for parsing queries


[Skip to Readme]

Modules

  • Database
    • TypedQuery
      • Database.TypedQuery.SQL
      • Database.TypedQuery.SQLParser
      • Database.TypedQuery.Types

Flags

Automatic Flags
NameDescriptionDefault
debug-typed-queries

Enable debug support

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.1, 0.1.1.1, 0.1.1.2
Dependencies aeson, base (>=4.5 && <5), bytestring, haskell-src-exts, haskell-src-meta, parsec, rawstring-qm, template-haskell, text, transformers [details]
License BSD-3-Clause
Copyright ©2014-2015 Marcin Tolysz
Author Marcin Tolysz
Maintainer tolysz@gmail.com
Category Database
Home page https://github.com/tolysz/typedquery
Uploaded by tolysz at 2015-01-10T14:45:57Z
Distributions
Reverse Dependencies 4 direct, 0 indirect [details]
Downloads 4552 total (24 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2016-12-12 [all 7 reports]

Readme for typedquery-0.1.0.2

[back to package description]

Coverage Status Build Status Latest Version

typedquery

Parser for SQL augmented with types

Till it finalised I would recomend installing it: with cabal -f debug-typed-queries just to see what is gonig on. As the SQL parser is not complete, and will need a major lift to make it readable and sane... however it works fine for all queries I need.

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.

  • genJsonQuery produces [Value]
  • genTypedQuery produces [(T1,...,Tn)] tuples, [T] or () all depending on the SQL query

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)]