@hackage sqlite-simple-interpolate0.1
Interpolated SQLite queries via quasiquotation
Categories
License
BSD-3-Clause
Maintainer
ruby0b
Links
Versions
Installation
Tested Compilers
Dependencies (6)
- base >=4.5 && <5
- haskell-src-meta >=0.6 && <0.9
- mtl >=2.1 && <2.3
- parsec ^>=3.1
- sqlite-simple >=0.1
- template-haskell >=2.16 && <2.19 Show all…
Dependents (0)
sqlite-simple-interpolate
Write natural SQL statements in Haskell using QuasiQuoters!
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.Char (toLower)
import qualified Database.SQLite.Simple as SQL
import Database.SQLite.Simple.QQ.Interpolated
import Control.Exception (bracket)
(&) = flip ($)
infixl 1 &
main :: IO ()
main = bracket (SQL.open ":memory:") SQL.close $ \conn -> do
conn & [iexecute|CREATE TABLE people (name TEXT, age INTEGER)|]
conn & [iexecute|INSERT INTO people VALUES ("clive", 40)|]
-- you can always use 'isql' directly but you'll have to use uncurry:
(uncurry $ SQL.execute conn) [isql|INSERT INTO people VALUES ("clive", 32)|]
ageSum <- conn & [ifold|SELECT age FROM people|] 0 (\acc (SQL.Only x) -> pure (acc + x))
print ageSum
let limit = 1
ages <- conn & [iquery|SELECT age FROM people WHERE name = ${map toLower "CLIVE"} LIMIT ${limit}|]
print (ages :: [SQL.Only Int])
Acknowledgements
This library is a fork of postgresql-simple-interpolate, adapted for use with sqlite-simple.
The original itself is basically just a copy of the here package by Taylor M. Hedberg with slight modifications!