We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The inet type exists already here
postgresql-binary has examples of encoding and decoding
The text was updated successfully, but these errors were encountered:
Here is a candidate version that uses postgresql-binary
postgresql-binary
import Network.IP.Addr import Database.PostgreSQL.Simple.ToField (ToField (..)) import Database.PostgreSQL.Simple.FromField (FromField (..), Field (..), returnError, ResultError (..)) import PostgreSQL.Binary.Encoding qualified as ENC import PostgreSQL.Binary.Decoding qualified as DEC import Database.PostgreSQL.Simple.TypeInfo.Static qualified as TI import qualified Data.Text as T instance ToField (NetAddr IP) where toField = toField . ENC.encodingBytes . ENC.inet {-# INLINE toField #-} instance FromField (NetAddr IP) where fromField f mbs = if typeOid f /= TI.uuidOid then returnError Incompatible f "" else case mbs of Nothing -> returnError UnexpectedNull f "" Just bs -> case DEC.valueParser DEC.inet bs of Left t -> returnError ConversionFailed f $ "Invalid inet: " <> T.unpack t Right inet -> pure uuid
Sorry, something went wrong.
No branches or pull requests
The inet type exists already here
postgresql-binary has examples of encoding and decoding
The text was updated successfully, but these errors were encountered: