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 0311c42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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 Int32 = CUShort
fromSQL Nothing = unexpectedNULL
fromSQL (Just n) = pure . fromIntegral $ n

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

instance FromSQL Word64 where
type PQBase Int32 = 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 = CULLon
toSQL n _ = putAsPtr (fromIntegral n)

-- CHAR

instance ToSQL Char where
Expand Down

0 comments on commit 0311c42

Please sign in to comment.