sqlite-simple-interpolate: Interpolated SQLite queries via quasiquotation

[ bsd3, database, library ] [ Propose Tags ]

This package provides Quasiquoters for writing SQLite queries with inline interpolation of values. The values are interpolated using toField from sqlite-simple. See the README for more details.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1, 0.2.0.0
Change log CHANGELOG.md
Dependencies base (>=4.5 && <5), haskell-src-meta (>=0.6 && <0.9), mtl (>=2.1 && <2.3), parsec (>=3.1 && <3.2), sqlite-simple (>=0.1), template-haskell (>=2.16 && <2.19) [details]
License BSD-3-Clause
Copyright ©2022 ruby0b ©2019 Elliot Cameron
Author ruby0b
Maintainer ruby0b
Revised Revision 1 made by ruby0b at 2022-05-30T19:38:06Z
Category Database
Home page https://github.com/ruby0b/sqlite-simple-interpolate
Source repo head: git clone git://github.com/ruby0b/sqlite-simple-interpolate.git
Uploaded by ruby0b at 2022-05-30T03:16:04Z
Distributions
Downloads 172 total (8 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2022-05-30 [all 2 reports]

Readme for sqlite-simple-interpolate-0.1

[back to package description]

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!