packages feed

hasql-2.2.0.0 / src / library / Hasql / Connection / ServerVersion.hs

module Hasql.Connection.ServerVersion  ( ServerVersion (..),    toText,    fromInt,    minimum,    -- * PQ operations    load,  )whereimport Hasql.Platform.Prelude hiding (minimum)import Pqi qualified as Pqimport TextBuilder qualifieddata ServerVersion = ServerVersion Int Int Int  deriving stock (Eq, Ord, Show)-- |-- >>> fromInt 10000-- ServerVersion 1 0 0---- >>> fromInt 100001-- ServerVersion 10 1 0---- >>> fromInt 110000-- ServerVersion 11 0 0---- >>> fromInt 90105-- ServerVersion 9 1 5---- >>> fromInt 90200-- ServerVersion 9 2 0---- Ref: https://www.postgresql.org/docs/18/libpq-status.html#LIBPQ-PQSERVERVERSIONfromInt :: Int -> ServerVersionfromInt x =  if x < 100_000    then fromPre10Int x    else fromPost10Int xfromPost10Int :: Int -> ServerVersionfromPost10Int x =  let (major, minor) = divMod x 10_000   in ServerVersion major minor 0fromPre10Int :: Int -> ServerVersionfromPre10Int = evalState do  patch <- state (swap . flip divMod 100)  minor <- state (swap . flip divMod 100)  major <- get  pure (ServerVersion major minor patch)toText :: ServerVersion -> TexttoText (ServerVersion major minor patch) =  (TextBuilder.toText . mconcat)    [ TextBuilder.decimal major,      ".",      TextBuilder.decimal minor,      ".",      TextBuilder.decimal patch    ]-- | Minimum supported version.minimum :: ServerVersionminimum = ServerVersion 9 0 0-- | Load from PQ connection.load :: Pq.Connection -> IO ServerVersionload connection =  fromInt <$> Pq.serverVersion connection