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

Versions0.1.0.0, 0.2.0, 0.3.0, 0.3.1
Change logNone available
Dependenciesbase (>=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]
LicenseMIT
Copyright(c) 2014 Hirotomo Moriwaki
AuthorHirotomoMoriwaki<philopon.dependence@gmail.com>
MaintainerHirotomoMoriwaki<philopon.dependence@gmail.com>
CategoryDatabase
Home pagehttps://github.com/philopon/sql-simple
Bug trackerhttps://github.com/philopon/sql-simple/issues
UploadedThu Jul 10 13:48:09 UTC 2014 by HirotomoMoriwaki
DistributionsNixOS:0.3.1
Downloads490 total (29 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

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