postgresql-typed 0.4.0 → 0.4.1
raw patch · 6 files changed
+22/−24 lines, 6 files
Files
- Database/PostgreSQL/Typed/Dynamic.hs +2/−2
- Database/PostgreSQL/Typed/Internal.hs +5/−5
- Database/PostgreSQL/Typed/Query.hs +2/−2
- Database/PostgreSQL/Typed/TH.hs +3/−5
- Database/PostgreSQL/Typed/Types.hs +8/−8
- postgresql-typed.cabal +2/−2
Database/PostgreSQL/Typed/Dynamic.hs view
@@ -105,10 +105,10 @@ -- Unlike most other TH functions, this does not require any database connection. pgSubstituteLiterals :: String -> TH.ExpQ pgSubstituteLiterals sql = TH.AppE (TH.VarE 'BS.concat) . TH.ListE <$> ssl (sqlSplitExprs sql) where- ssl :: SQLSplit String True -> TH.Q [TH.Exp]+ ssl :: SQLSplit String 'True -> TH.Q [TH.Exp] ssl (SQLLiteral s l) = (TH.VarE 'fromString `TH.AppE` stringE s :) <$> ssp l ssl SQLSplitEnd = return []- ssp :: SQLSplit String False -> TH.Q [TH.Exp]+ ssp :: SQLSplit String 'False -> TH.Q [TH.Exp] ssp (SQLPlaceholder e l) = do v <- either (fail . (++) ("Failed to parse expression {" ++ e ++ "}: ")) return $ parseExp e (TH.VarE 'pgSafeLiteral `TH.AppE` v :) <$> ssl l
Database/PostgreSQL/Typed/Internal.hs view
@@ -21,15 +21,15 @@ fromString = stringE data SQLSplit a (literal :: Bool) where- SQLLiteral :: String -> SQLSplit a False -> SQLSplit a True- SQLPlaceholder :: a -> SQLSplit a True -> SQLSplit a False+ SQLLiteral :: String -> SQLSplit a 'False -> SQLSplit a 'True+ SQLPlaceholder :: a -> SQLSplit a 'True -> SQLSplit a 'False SQLSplitEnd :: SQLSplit a any -sqlCons :: Char -> SQLSplit a True -> SQLSplit a True+sqlCons :: Char -> SQLSplit a 'True -> SQLSplit a 'True sqlCons c (SQLLiteral s l) = SQLLiteral (c : s) l sqlCons c SQLSplitEnd = SQLLiteral [c] SQLSplitEnd -sqlSplitExprs :: String -> SQLSplit String True+sqlSplitExprs :: String -> SQLSplit String 'True sqlSplitExprs ('$':'$':'{':s) = sqlCons '$' $ sqlCons '{' $ sqlSplitExprs s sqlSplitExprs ('$':'{':s) | (e, '}':r) <- break (\c -> c == '{' || c == '}') s = SQLLiteral "" $ SQLPlaceholder e $ sqlSplitExprs r@@ -37,7 +37,7 @@ sqlSplitExprs (c:s) = sqlCons c $ sqlSplitExprs s sqlSplitExprs [] = SQLSplitEnd -sqlSplitParams :: String -> SQLSplit Int True+sqlSplitParams :: String -> SQLSplit Int 'True sqlSplitParams ('$':'$':d:s) | isDigit d = sqlCons '$' $ sqlCons d $ sqlSplitParams s sqlSplitParams ('$':s@(d:_)) | isDigit d, [(n, r)] <- readDec s = SQLLiteral "" $ SQLPlaceholder n $ sqlSplitParams r sqlSplitParams (c:s) = sqlCons c $ sqlSplitParams s
Database/PostgreSQL/Typed/Query.hs view
@@ -118,10 +118,10 @@ -- Embedded expressions may not contain @{@ or @}@. sqlPlaceholders :: String -> (String, [String]) sqlPlaceholders = ssl 1 . sqlSplitExprs where- ssl :: Int -> SQLSplit String True -> (String, [String])+ ssl :: Int -> SQLSplit String 'True -> (String, [String]) ssl n (SQLLiteral s l) = first (s ++) $ ssp n l ssl _ SQLSplitEnd = ("", [])- ssp :: Int -> SQLSplit String False -> (String, [String])+ ssp :: Int -> SQLSplit String 'False -> (String, [String]) ssp n (SQLPlaceholder e l) = (('$':show n) ++) *** (e :) $ ssl (succ n) l ssp _ SQLSplitEnd = ("", [])
Database/PostgreSQL/Typed/TH.hs view
@@ -76,11 +76,9 @@ tpgLoadTypes :: TPGState -> IO TPGState tpgLoadTypes tpg = do- -- defer loading types until they're needed- tl <- unsafeInterleaveIO $ pgSimpleQuery (tpgConnection tpg) $ BSLC.pack "SELECT typ.oid, format_type(CASE WHEN typtype = 'd' THEN typbasetype ELSE typ.oid END, -1) FROM pg_catalog.pg_type typ JOIN pg_catalog.pg_namespace nsp ON typnamespace = nsp.oid WHERE nspname <> 'pg_toast' AND nspname <> 'information_schema' ORDER BY typ.oid"- return $ tpg{ tpgTypes = IntMap.fromAscList $ map (\[to, tn] ->- (fromIntegral (pgDecodeRep to :: OID), pgDecodeRep tn)) $ snd tl- }+ t <- IntMap.fromAscList . map (\[to, tn] -> (fromIntegral (pgDecodeRep to :: OID), pgDecodeRep tn)) .+ snd <$> pgSimpleQuery (tpgConnection tpg) (BSLC.pack "SELECT typ.oid, format_type(CASE WHEN typtype = 'd' THEN typbasetype ELSE typ.oid END, -1) FROM pg_catalog.pg_type typ JOIN pg_catalog.pg_namespace nsp ON typnamespace = nsp.oid WHERE nspname <> 'pg_toast' AND nspname <> 'information_schema' ORDER BY typ.oid")+ return tpg{ tpgTypes = t } tpgInit :: PGConnection -> IO TPGState tpgInit c = tpgLoadTypes TPGState{ tpgConnection = c, tpgTypes = undefined }
Database/PostgreSQL/Typed/Types.hs view
@@ -318,17 +318,17 @@ pgDecode _ = BSU.toString BIN_DEC((T.unpack .) . binDec BinD.text) -instance PGStringType t => PGParameter t BS.ByteString where+instance {-# OVERLAPPABLE #-} PGStringType t => PGParameter t BS.ByteString where pgEncode _ = id BIN_ENC(BinE.text . Left . TE.decodeUtf8)-instance PGStringType t => PGColumn t BS.ByteString where+instance {-# OVERLAPPABLE #-} PGStringType t => PGColumn t BS.ByteString where pgDecode _ = id BIN_DEC((TE.encodeUtf8 .) . binDec BinD.text) -instance PGStringType t => PGParameter t BSL.ByteString where+instance {-# OVERLAPPABLE #-} PGStringType t => PGParameter t BSL.ByteString where pgEncode _ = BSL.toStrict BIN_ENC(BinE.text . Right . TLE.decodeUtf8)-instance PGStringType t => PGColumn t BSL.ByteString where+instance {-# OVERLAPPABLE #-} PGStringType t => PGColumn t BSL.ByteString where pgDecode _ = BSL.fromStrict BIN_DEC((BSL.fromStrict .) . (TE.encodeUtf8 .) . binDec BinD.text) @@ -373,18 +373,18 @@ unhex = fromIntegral . digitToInt . w2c instance PGType "bytea" where BIN_COL-instance PGParameter "bytea" BSL.ByteString where+instance {-# OVERLAPPING #-} PGParameter "bytea" BSL.ByteString where pgEncode _ = encodeBytea . BSB.lazyByteStringHex pgLiteral t = pgQuoteUnsafe . pgEncode t BIN_ENC(BinE.bytea . Right)-instance PGColumn "bytea" BSL.ByteString where+instance {-# OVERLAPPING #-} PGColumn "bytea" BSL.ByteString where pgDecode _ = BSL.pack . decodeBytea BIN_DEC((BSL.fromStrict .) . binDec BinD.bytea)-instance PGParameter "bytea" BS.ByteString where+instance {-# OVERLAPPING #-} PGParameter "bytea" BS.ByteString where pgEncode _ = encodeBytea . BSB.byteStringHex pgLiteral t = pgQuoteUnsafe . pgEncode t BIN_ENC(BinE.bytea . Left)-instance PGColumn "bytea" BS.ByteString where+instance {-# OVERLAPPING #-} PGColumn "bytea" BS.ByteString where pgDecode _ = BS.pack . decodeBytea BIN_DEC(binDec BinD.bytea)
postgresql-typed.cabal view
@@ -1,12 +1,12 @@ Name: postgresql-typed-Version: 0.4.0+Version: 0.4.1 Cabal-Version: >= 1.8 License: BSD3 License-File: COPYING Copyright: 2010-2013 Chris Forno, 2014-2015 Dylan Simon Author: Dylan Simon Maintainer: Dylan Simon <dylan-pgtyped@dylex.net>-Stability: alpha+Stability: beta Bug-Reports: https://github.com/dylex/postgresql-typed/issues Homepage: https://github.com/dylex/postgresql-typed Category: Database