The sql-simple package

[Tags:library, mit]

please read README.md https://github.com/philopon/sql-simple/blob/master/README.md


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.2.0, 0.3.0, 0.3.1
Dependencies base (>=4.6 && <4.8), containers (==0.5.*), exceptions (==0.6.*), monad-control (==0.3.*), tagged (==0.7.*), text (==1.1.*), transformers (==0.4.*), transformers-base (==0.4.*) [details]
License MIT
Copyright (c) 2014 Hirotomo Moriwaki
Author HirotomoMoriwaki<philopon.dependence@gmail.com>
Maintainer HirotomoMoriwaki<philopon.dependence@gmail.com>
Stability Unknown
Category Database
Home page https://github.com/philopon/sql-simple
Bug tracker https://github.com/philopon/sql-simple/issues
Uploaded Thu Jul 10 13:48:09 UTC 2014 by HirotomoMoriwaki
Distributions NixOS:0.3.1
Downloads 704 total (19 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for sql-simple

Readme for sql-simple-0.3.1

sql-simple Build Status

common middle-level sql client.

tutorial

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ConstraintKinds #-}

import Control.Applicative
import Database.Sql.Simple
import Database.Sql.Simple.SQLite
import Database.Sql.Simple.PostgreSQL
import Database.Sql.Simple.Pool

-- you must specify 1st type variable of Sql Monad.
-- by explicit type signature,
testQuery :: (ToRow conn (Only Int), FromRow conn (Only Int), Backend conn) 
          => conn -> Sql '[SQLite, PostgreSQL] [Int]
testQuery c = do
    execute_ c "CREATE TABLE test (id int)"
    execute  c "INSERT INTO test VALUES (?)" (Only (1 :: Int))
    map fromOnly <$> query_ c "SELECT * FROM test"

-- or sql function(testQuery' equivalent to testQuery).
testQuery' c = sql (sqlite +:+ postgreSQL) $ do
    execute_ c "CREATE TABLE test (id int)"
    execute  c "INSERT INTO test VALUES (?)" (Only (1 :: Int))
    i <- map fromOnly <$> query_ c "SELECT * FROM test"
    return (i :: [Int])

-- you can specify backend specific Query.
specificQuery :: Backend conn => conn -> Sql '[SQLite, PostgreSQL] ()
specificQuery c =
    execute_ c (specify sqlite "[sqlite query]" "[common query]")

main :: IO ()
main = do
    -- l <- withConnection ("test.sqlite3" :: ConnectInfo SQLite) testQuery
    l <- withConnection (ConnectionPool def "test.sqlite3" :: ConnectInfo (Pool SQLite)) testQuery
    -- l <- withConnection (def :: ConnectInfo PostgreSQL) testQuery
    print l