MyNixOS website logo
Description

Parser for SQL augmented with types.

Base package for parsing queries, the idea is to use SQL language to write queries, and TH to make them usable with haskell

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

  • https://github.com/tolysz/mysql-simple-typed
  • https://github.com/tolysz/sqlite-simple-typed
  • https://github.com/tolysz/postgresql-simple-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.


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

Version

0.1.1.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows