mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-01 22:02:07 +03:00
Flip arguments of runQuery.
This commit is contained in:
parent
f9ecc2aae8
commit
9709ba1296
@ -127,15 +127,15 @@ runPreparedQuery' ps = runStatement' . bind ps
|
||||
-- | Prepare SQL, bind parameters, execute statement and lazily fetch all records.
|
||||
runQuery :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a)
|
||||
=> conn -- ^ Database connection
|
||||
-> p -- ^ Parameter type
|
||||
-> Query p a -- ^ Query to get record type 'a' requires parameter 'p'
|
||||
-> p -- ^ Parameter type
|
||||
-> IO [a] -- ^ Action to get records
|
||||
runQuery conn p = (>>= \ps -> runPreparedQuery ps p) . prepare conn
|
||||
runQuery conn q p = prepare conn q >>= (`runPreparedQuery` p)
|
||||
|
||||
-- | Strict version of 'runQuery'.
|
||||
runQuery' :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a)
|
||||
=> conn -- ^ Database connection
|
||||
-> p -- ^ Parameter type
|
||||
-> Query p a -- ^ Query to get record type 'a' requires parameter 'p'
|
||||
-> p -- ^ Parameter type
|
||||
-> IO [a] -- ^ Action to get records
|
||||
runQuery' conn p = (>>= \ps -> runPreparedQuery' ps p) . prepare conn
|
||||
runQuery' conn q p = prepare conn q >>= (`runPreparedQuery'` p)
|
||||
|
@ -64,7 +64,7 @@ getPrimaryKey' :: IConnection conn
|
||||
getPrimaryKey' conn scm' tbl' = do
|
||||
let tbl = map toUpper tbl'
|
||||
scm = map toUpper scm'
|
||||
primCols <- runQuery' conn (scm, tbl) primaryKeyQuerySQL
|
||||
primCols <- runQuery' conn primaryKeyQuerySQL (scm, tbl)
|
||||
let primaryKeyCols = normalizeColumn `fmap` primCols
|
||||
putLog $ "getPrimaryKey: primary key = " ++ show primaryKeyCols
|
||||
|
||||
@ -79,8 +79,8 @@ getFields' :: IConnection conn
|
||||
getFields' tmap conn scm' tbl' = do
|
||||
let tbl = map toUpper tbl'
|
||||
scm = map toUpper scm'
|
||||
|
||||
cols <- runQuery' conn (scm, tbl) columnsQuerySQL
|
||||
|
||||
cols <- runQuery' conn columnsQuerySQL (scm, tbl)
|
||||
case cols of
|
||||
[] -> compileErrorIO
|
||||
$ "getFields: No columns found: schema = " ++ scm ++ ", table = " ++ tbl
|
||||
|
@ -65,13 +65,13 @@ getPrimaryKey' :: IConnection conn
|
||||
getPrimaryKey' conn scm' tbl' = do
|
||||
let scm = map toLower scm'
|
||||
tbl = map toLower tbl'
|
||||
mayKeyLen <- runQuery' conn (scm, tbl) primaryKeyLengthQuerySQL
|
||||
mayKeyLen <- runQuery' conn primaryKeyLengthQuerySQL (scm, tbl)
|
||||
case mayKeyLen of
|
||||
[] -> do
|
||||
putLog $ "getPrimaryKey: Primary key not found."
|
||||
return []
|
||||
[keyLen] -> do
|
||||
primCols <- runQuery' conn (scm, tbl) (primaryKeyQuerySQL keyLen)
|
||||
primCols <- runQuery' conn (primaryKeyQuerySQL keyLen) (scm, tbl)
|
||||
let primaryKeyCols = normalizeColumn `fmap` primCols
|
||||
putLog $ "getPrimaryKey: primary key = " ++ show primaryKeyCols
|
||||
return primaryKeyCols
|
||||
@ -88,7 +88,7 @@ getFields' :: IConnection conn
|
||||
getFields' tmap conn scm' tbl' = do
|
||||
let scm = map toLower scm'
|
||||
tbl = map toLower tbl'
|
||||
cols <- runQuery' conn (scm, tbl) columnQuerySQL
|
||||
cols <- runQuery' conn columnQuerySQL (scm, tbl)
|
||||
case cols of
|
||||
[] -> compileErrorIO
|
||||
$ "getFields: No columns found: schema = " ++ scm ++ ", table = " ++ tbl
|
||||
@ -111,4 +111,3 @@ driverPostgreSQL :: IConnection conn => Driver conn
|
||||
driverPostgreSQL =
|
||||
emptyDriver { getFieldsWithMap = getFields' }
|
||||
{ getPrimaryKey = getPrimaryKey' }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user