Skip to content

Commit 4d216e4

Browse files
From/ToSQL instances for Word16, Word32, Word64
1 parent 4c29aa0 commit 4d216e4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/Database/PostgreSQL/PQTypes/Format.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ instance PQFormat Float where
8585
instance PQFormat Double where
8686
pqFormat = BS.pack "%float8"
8787

88+
instance PQFormat Word16 where
89+
pqFormat = BS.pack "%word2"
90+
91+
instance PQFormat Word32 where
92+
pqFormat = BS.pack "%word4"
93+
94+
instance PQFormat Word64 where
95+
pqFormat = BS.pack "%word8"
96+
8897
-- CHAR
8998

9099
instance PQFormat Char where

src/Database/PostgreSQL/PQTypes/FromSQL.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ instance FromSQL Double where
6868
fromSQL Nothing = unexpectedNULL
6969
fromSQL (Just n) = pure . realToFrac $ n
7070

71+
instance FromSQL Word16 where
72+
type PQBase Word16 = CUShort
73+
fromSQL Nothing = unexpectedNULL
74+
fromSQL (Just n) = pure . fromIntegral $ n
75+
76+
instance FromSQL Word32 where
77+
type PQBase Word32 = CUInt
78+
fromSQL Nothing = unexpectedNULL
79+
fromSQL (Just n) = pure . fromIntegral $ n
80+
81+
instance FromSQL Word64 where
82+
type PQBase Word64 = CULLong
83+
fromSQL Nothing = unexpectedNULL
84+
fromSQL (Just n) = pure . fromIntegral $ n
85+
7186
-- CHAR
7287

7388
instance FromSQL Char where

src/Database/PostgreSQL/PQTypes/ToSQL.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ instance ToSQL Double where
8484
type PQDest Double = CDouble
8585
toSQL n _ = putAsPtr (realToFrac n)
8686

87+
instance ToSQL Word16 where
88+
type PQDest Word16 = CUShort
89+
toSQL n _ = putAsPtr (fromIntegral n)
90+
91+
instance ToSQL Word32 where
92+
type PQDest Word32 = CUInt
93+
toSQL n _ = putAsPtr (fromIntegral n)
94+
95+
instance ToSQL Word64 where
96+
type PQDest Word64 = CULLong
97+
toSQL n _ = putAsPtr (fromIntegral n)
98+
8799
-- CHAR
88100

89101
instance ToSQL Char where

0 commit comments

Comments
 (0)