Skip to content

Commit

Permalink
From/ToSQL instances for Word16, Word32, Word64
Browse files Browse the repository at this point in the history
  • Loading branch information
theophile-scrive committed Jan 7, 2025
1 parent 4c29aa0 commit 4d216e4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Database/PostgreSQL/PQTypes/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ instance PQFormat Float where
instance PQFormat Double where
pqFormat = BS.pack "%float8"

instance PQFormat Word16 where
pqFormat = BS.pack "%word2"

instance PQFormat Word32 where
pqFormat = BS.pack "%word4"

instance PQFormat Word64 where
pqFormat = BS.pack "%word8"

-- CHAR

instance PQFormat Char where
Expand Down
15 changes: 15 additions & 0 deletions src/Database/PostgreSQL/PQTypes/FromSQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ instance FromSQL Double where
fromSQL Nothing = unexpectedNULL
fromSQL (Just n) = pure . realToFrac $ n

instance FromSQL Word16 where
type PQBase Word16 = CUShort
fromSQL Nothing = unexpectedNULL
fromSQL (Just n) = pure . fromIntegral $ n

instance FromSQL Word32 where
type PQBase Word32 = CUInt
fromSQL Nothing = unexpectedNULL
fromSQL (Just n) = pure . fromIntegral $ n

instance FromSQL Word64 where
type PQBase Word64 = CULLong
fromSQL Nothing = unexpectedNULL
fromSQL (Just n) = pure . fromIntegral $ n

-- CHAR

instance FromSQL Char where
Expand Down
12 changes: 12 additions & 0 deletions src/Database/PostgreSQL/PQTypes/ToSQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ instance ToSQL Double where
type PQDest Double = CDouble
toSQL n _ = putAsPtr (realToFrac n)

instance ToSQL Word16 where
type PQDest Word16 = CUShort
toSQL n _ = putAsPtr (fromIntegral n)

instance ToSQL Word32 where
type PQDest Word32 = CUInt
toSQL n _ = putAsPtr (fromIntegral n)

instance ToSQL Word64 where
type PQDest Word64 = CULLong
toSQL n _ = putAsPtr (fromIntegral n)

-- CHAR

instance ToSQL Char where
Expand Down

0 comments on commit 4d216e4

Please sign in to comment.