postgresql-simple 0.1.4.3 → 0.2
raw patch · 6 files changed
+145/−144 lines, 6 files
Files
- CONTRIBUTORS +6/−0
- postgresql-simple.cabal +5/−2
- src/Database/PostgreSQL/Simple.hs +4/−2
- src/Database/PostgreSQL/Simple/BuiltinTypes.hs +117/−117
- src/Database/PostgreSQL/Simple/FromField.hs +9/−19
- src/Database/PostgreSQL/Simple/ToField.hs +4/−4
+ CONTRIBUTORS view
@@ -0,0 +1,6 @@+Bryan O'Sullivan <bos@serpentine.com>+Leon P Smith <leon@melding-monads.com>+Felipe Lessa <felipe.lessa@gmail.com>+Ozgun Ataman <ozataman@gmail.com>+Joey Adams <joeyadams3.14159@gmail.com>+Rekado <rekado@elephly.net>
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.1.4.3+Version: 0.2 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -14,6 +14,9 @@ Cabal-version: >= 1.9.2 +extra-source-files:+ CONTRIBUTORS+ Library hs-source-dirs: src Exposed-modules:@@ -64,7 +67,7 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.1.4.3+ tag: v0.2 test-suite test type: exitcode-stdio-1.0
src/Database/PostgreSQL/Simple.hs view
@@ -56,6 +56,8 @@ Base.ConnectInfo(..) , Connection , Query+ , ToRow+ , FromRow , In(..) , Binary(..) , Only(..)@@ -310,7 +312,7 @@ utf8ToString = T.unpack . TE.decodeUtf8 sub (Plain b) = pure b sub (Escape s) = quote <$> escapeStringConn conn s- sub (EscapeBytea s) = quote <$> escapeByteaConn conn s+ sub (EscapeByteA s) = quote <$> escapeByteaConn conn s sub (Many ys) = mconcat <$> mapM sub ys split s = fromByteString h : if B.null t then [] else split (B.tail t) where (h,t) = B.break (=='?') s@@ -678,7 +680,7 @@ } where twiddle (Plain b) = toByteString b twiddle (Escape s) = s- twiddle (EscapeBytea s) = s+ twiddle (EscapeByteA s) = s twiddle (Many ys) = B.concat (map twiddle ys) -- $use
src/Database/PostgreSQL/Simple/BuiltinTypes.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------ -- | -- Module: Database.PostgreSQL.Simple.BuiltinTypes--- Copyright: (c) 2011 Leon P Smith+-- Copyright: (c) 2011-2012 Leon P Smith -- License: BSD3 -- Maintainer: Leon P Smith <leon@melding-monads.com> -- Stability: experimental@@ -27,13 +27,13 @@ data BuiltinType = Bool- | Bytea+ | ByteA | Char | Name | Int8 | Int2 | Int4- | Regproc+ | RegProc | Text | Oid | Tid@@ -41,7 +41,7 @@ | Cid | Xml | Point- | Lseg+ | LSeg | Path | Box | Polygon@@ -49,88 +49,88 @@ | Cidr | Float4 | Float8- | Abstime- | Reltime- | Tinterval+ | AbsTime+ | RelTime+ | TInterval | Unknown | Circle | Money- | Macaddr+ | MacAddr | Inet- | Bpchar- | Varchar+ | BpChar+ | VarChar | Date | Time | Timestamp- | TimestampWithTimeZone+ | TimestampTZ | Interval- | TimeWithTimeZone+ | TimeTZ | Bit- | Varbit+ | VarBit | Numeric- | Refcursor+ | RefCursor | Record | Void deriving (Eq, Ord, Enum, Bounded, Read, Show, Typeable) builtin2oid :: BuiltinType -> PQ.Oid builtin2oid typ = PQ.Oid $ case typ of- Bool -> 16- Bytea -> 17- Char -> 18- Name -> 19- Int8 -> 20- Int2 -> 21- Int4 -> 23- Regproc -> 24- Text -> 25- Oid -> 26- Tid -> 27- Xid -> 28- Cid -> 29- Xml -> 142- Point -> 600- Lseg -> 601- Path -> 602- Box -> 603- Polygon -> 604- Line -> 628- Cidr -> 650- Float4 -> 700- Float8 -> 701- Abstime -> 702- Reltime -> 703- Tinterval -> 704- Unknown -> 705- Circle -> 718- Money -> 790- Macaddr -> 829- Inet -> 869- Bpchar -> 1042- Varchar -> 1043- Date -> 1082- Time -> 1083- Timestamp -> 1114- TimestampWithTimeZone -> 1184- Interval -> 1186- TimeWithTimeZone -> 1266- Bit -> 1560- Varbit -> 1562- Numeric -> 1700- Refcursor -> 1790- Record -> 2249- Void -> 2278+ Bool -> 16+ ByteA -> 17+ Char -> 18+ Name -> 19+ Int8 -> 20+ Int2 -> 21+ Int4 -> 23+ RegProc -> 24+ Text -> 25+ Oid -> 26+ Tid -> 27+ Xid -> 28+ Cid -> 29+ Xml -> 142+ Point -> 600+ LSeg -> 601+ Path -> 602+ Box -> 603+ Polygon -> 604+ Line -> 628+ Cidr -> 650+ Float4 -> 700+ Float8 -> 701+ AbsTime -> 702+ RelTime -> 703+ TInterval -> 704+ Unknown -> 705+ Circle -> 718+ Money -> 790+ MacAddr -> 829+ Inet -> 869+ BpChar -> 1042+ VarChar -> 1043+ Date -> 1082+ Time -> 1083+ Timestamp -> 1114+ TimestampTZ -> 1184+ Interval -> 1186+ TimeTZ -> 1266+ Bit -> 1560+ VarBit -> 1562+ Numeric -> 1700+ RefCursor -> 1790+ Record -> 2249+ Void -> 2278 oid2builtin :: PQ.Oid -> Maybe BuiltinType oid2builtin (PQ.Oid x) = case x of 16 -> Just Bool- 17 -> Just Bytea+ 17 -> Just ByteA 18 -> Just Char 19 -> Just Name 20 -> Just Int8 21 -> Just Int2 23 -> Just Int4- 24 -> Just Regproc+ 24 -> Just RegProc 25 -> Just Text 26 -> Just Oid 27 -> Just Tid@@ -138,7 +138,7 @@ 29 -> Just Cid 142 -> Just Xml 600 -> Just Point- 601 -> Just Lseg+ 601 -> Just LSeg 602 -> Just Path 603 -> Just Box 604 -> Just Polygon@@ -146,77 +146,77 @@ 650 -> Just Cidr 700 -> Just Float4 701 -> Just Float8- 702 -> Just Abstime- 703 -> Just Reltime- 704 -> Just Tinterval+ 702 -> Just AbsTime+ 703 -> Just RelTime+ 704 -> Just TInterval 705 -> Just Unknown 718 -> Just Circle 790 -> Just Money- 829 -> Just Macaddr+ 829 -> Just MacAddr 869 -> Just Inet- 1042 -> Just Bpchar- 1043 -> Just Varchar+ 1042 -> Just BpChar+ 1043 -> Just VarChar 1082 -> Just Date 1083 -> Just Time 1114 -> Just Timestamp- 1184 -> Just TimestampWithTimeZone+ 1184 -> Just TimestampTZ 1186 -> Just Interval- 1266 -> Just TimeWithTimeZone+ 1266 -> Just TimeTZ 1560 -> Just Bit- 1562 -> Just Varbit+ 1562 -> Just VarBit 1700 -> Just Numeric- 1790 -> Just Refcursor+ 1790 -> Just RefCursor 2249 -> Just Record 2278 -> Just Void _ -> Nothing builtin2typname :: BuiltinType -> ByteString builtin2typname typ = case typ of- Bool -> bool- Bytea -> bytea- Char -> char- Name -> name- Int8 -> int8- Int2 -> int2- Int4 -> int4- Regproc -> regproc- Text -> text- Oid -> oid- Tid -> tid- Xid -> xid- Cid -> cid- Xml -> xml- Point -> point- Lseg -> lseg- Path -> path- Box -> box- Polygon -> polygon- Line -> line- Cidr -> cidr- Float4 -> float4- Float8 -> float8- Abstime -> abstime- Reltime -> reltime- Tinterval -> tinterval- Unknown -> unknown- Circle -> circle- Money -> money- Macaddr -> macaddr- Inet -> inet- Bpchar -> bpchar- Varchar -> varchar- Date -> date- Time -> time- Timestamp -> timestamp- TimestampWithTimeZone -> timestamptz- Interval -> interval- TimeWithTimeZone -> timetz- Bit -> bit- Varbit -> varbit- Numeric -> numeric- Refcursor -> refcursor- Record -> record- Void -> void+ Bool -> bool+ ByteA -> bytea+ Char -> char+ Name -> name+ Int8 -> int8+ Int2 -> int2+ Int4 -> int4+ RegProc -> regproc+ Text -> text+ Oid -> oid+ Tid -> tid+ Xid -> xid+ Cid -> cid+ Xml -> xml+ Point -> point+ LSeg -> lseg+ Path -> path+ Box -> box+ Polygon -> polygon+ Line -> line+ Cidr -> cidr+ Float4 -> float4+ Float8 -> float8+ AbsTime -> abstime+ RelTime -> reltime+ TInterval -> tinterval+ Unknown -> unknown+ Circle -> circle+ Money -> money+ MacAddr -> macaddr+ Inet -> inet+ BpChar -> bpchar+ VarChar -> varchar+ Date -> date+ Time -> time+ Timestamp -> timestamp+ TimestampTZ -> timestamptz+ Interval -> interval+ TimeTZ -> timetz+ Bit -> bit+ VarBit -> varbit+ Numeric -> numeric+ RefCursor -> refcursor+ Record -> record+ Void -> void oid2typname :: PQ.Oid -> Maybe ByteString oid2typname (PQ.Oid x) = case x of
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -53,8 +53,7 @@ import Data.Int (Int16, Int32, Int64) import Data.List (foldl') import Data.Ratio (Ratio)-import Data.Time ( UTCTime, ZonedTime, LocalTime, Day, TimeOfDay- , localTimeToUTC, utc )+import Data.Time ( UTCTime, ZonedTime, LocalTime, Day, TimeOfDay ) import Data.Typeable (Typeable, typeOf) import Data.Word (Word64) import Database.PostgreSQL.Simple.Internal@@ -161,7 +160,7 @@ unBinary (Binary x) = x instance FromField SB.ByteString where- fromField f dat = if typeOid f == builtin2oid Bytea+ fromField f dat = if typeOid f == builtin2oid ByteA then unBinary <$> fromField f dat else doFromField f okText' (pure . B.copy) dat @@ -196,19 +195,10 @@ fromField f dat = ST.unpack <$> fromField f dat instance FromField UTCTime where- fromField f =- case oid2builtin (typeOid f) of- Just TimestampWithTimeZone -> doIt id parseUTCTime- Just Timestamp -> doIt (localTimeToUTC utc) parseLocalTime -- deprecated- _ -> const $ returnError Incompatible f ""- where- doIt _finish _parse Nothing- = returnError UnexpectedNull f ""- doIt finish parse (Just bs)- = either (returnError ConversionFailed f) (pure . finish) (parse bs)+ fromField = ff TimestampTZ "UTCTime" parseUTCTime instance FromField ZonedTime where- fromField = ff TimestampWithTimeZone "ZonedTime" parseZonedTime+ fromField = ff TimestampTZ "ZonedTime" parseZonedTime instance FromField LocalTime where fromField = ff Timestamp "LocalTime" parseLocalTime@@ -220,10 +210,10 @@ fromField = ff Time "TimeOfDay" parseTimeOfDay instance FromField UTCTimestamp where- fromField = ff TimestampWithTimeZone "UTCTimestamp" parseUTCTimestamp+ fromField = ff TimestampTZ "UTCTimestamp" parseUTCTimestamp instance FromField ZonedTimestamp where- fromField = ff TimestampWithTimeZone "ZonedTimestamp" parseZonedTimestamp+ fromField = ff TimestampTZ "ZonedTimestamp" parseZonedTimestamp instance FromField LocalTimestamp where fromField = ff Timestamp "LocalTimestamp" parseLocalTimestamp@@ -261,9 +251,9 @@ compat (Compat a) (Compat b) = a .&. b /= 0 okText, okText', okBinary, ok16, ok32, ok64, okInt :: Compat-okText = mkCompats [Name,Text,Char,Bpchar,Varchar]-okText' = mkCompats [Name,Text,Char,Bpchar,Varchar,Unknown]-okBinary = mkCompats [Bytea]+okText = mkCompats [Name,Text,Char,BpChar,VarChar]+okText' = mkCompats [Name,Text,Char,BpChar,VarChar,Unknown]+okBinary = mkCompats [ByteA] ok16 = mkCompats [Int2] ok32 = mkCompats [Int2,Int4] ok64 = mkCompats [Int2,Int4,Int8]
src/Database/PostgreSQL/Simple/ToField.hs view
@@ -53,7 +53,7 @@ -- ^ Escape and enclose in quotes before substituting. Use for all -- text-like types, and anything else that may contain unsafe -- characters when rendered.- | EscapeBytea ByteString+ | EscapeByteA ByteString -- ^ Escape binary data for use as a @bytea@ literal. Include surrounding -- quotes. This is used by the 'Binary' newtype wrapper. | Many [Action]@@ -63,7 +63,7 @@ instance Show Action where show (Plain b) = "Plain " ++ show (toByteString b) show (Escape b) = "Escape " ++ show b- show (EscapeBytea b) = "EscapeBytea " ++ show b+ show (EscapeByteA b) = "EscapeByteA " ++ show b show (Many b) = "Many " ++ show b -- | A type that may be used as a single parameter to a SQL query.@@ -158,11 +158,11 @@ {-# INLINE toField #-} instance ToField (Binary SB.ByteString) where- toField (Binary bs) = EscapeBytea bs+ toField (Binary bs) = EscapeByteA bs {-# INLINE toField #-} instance ToField (Binary LB.ByteString) where- toField (Binary bs) = (EscapeBytea . SB.concat . LB.toChunks) bs+ toField (Binary bs) = (EscapeByteA . SB.concat . LB.toChunks) bs {-# INLINE toField #-} instance ToField SB.ByteString where