mirror of
https://github.com/postgres-haskell/postgres-wire.git
synced 2024-11-22 14:51:09 +03:00
Small improvements
This commit is contained in:
parent
f7ed159216
commit
4ac1d9f9d3
@ -1,6 +1,7 @@
|
|||||||
module Database.PostgreSQL.Protocol.Types where
|
module Database.PostgreSQL.Protocol.Types where
|
||||||
|
|
||||||
-- TODO
|
-- Exports all declared datatypes
|
||||||
|
--
|
||||||
-- * COPY subprotocol commands
|
-- * COPY subprotocol commands
|
||||||
--
|
--
|
||||||
-- * function call, is deprecated by postgres
|
-- * function call, is deprecated by postgres
|
||||||
@ -28,14 +29,19 @@ newtype DatabaseName = DatabaseName ByteString deriving (Show)
|
|||||||
newtype MD5Salt = MD5Salt ByteString deriving (Show)
|
newtype MD5Salt = MD5Salt ByteString deriving (Show)
|
||||||
|
|
||||||
data PasswordText
|
data PasswordText
|
||||||
= PasswordPlain ByteString
|
= PasswordPlain !ByteString
|
||||||
| PasswordMD5 ByteString
|
| PasswordMD5 !ByteString
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
newtype ServerProcessId = ServerProcessId Int32 deriving (Show)
|
newtype ServerProcessId = ServerProcessId Int32 deriving (Show)
|
||||||
newtype ServerSecretKey = ServerSecretKey Int32 deriving (Show)
|
newtype ServerSecretKey = ServerSecretKey Int32 deriving (Show)
|
||||||
|
|
||||||
newtype RowsCount = RowsCount Word deriving (Show)
|
-- | Server version contains major, minor, revision numbers.
|
||||||
|
-- Examples:
|
||||||
|
-- 9.6.0 ServerVersion 9 6 0 ""
|
||||||
|
-- 10.1beta2 - ServerVersion 10 1 0 "beta2"
|
||||||
|
data ServerVersion = ServerVersion !Word8 !Word8 !Word8 !ByteString
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
-- | Maximum number of rows to return, if portal contains a query that
|
-- | Maximum number of rows to return, if portal contains a query that
|
||||||
-- returns rows (ignored otherwise). Zero denotes "no limit".
|
-- returns rows (ignored otherwise). Zero denotes "no limit".
|
||||||
@ -60,13 +66,9 @@ data CommandResult
|
|||||||
| CommandOk
|
| CommandOk
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- | Server version contains major, minor, revision numbers.
|
newtype RowsCount = RowsCount Word deriving (Show)
|
||||||
-- Examples:
|
|
||||||
-- 9.6.0 ServerVersion 9 6 0 ""
|
|
||||||
-- 10.1beta2 - ServerVersion 10 1 0 "beta2"
|
|
||||||
data ServerVersion = ServerVersion Word8 Word8 Word8 ByteString
|
|
||||||
deriving (Eq, Show)
|
|
||||||
|
|
||||||
|
-- | Status of transaction block returned by ReadyForQuery.
|
||||||
data TransactionStatus
|
data TransactionStatus
|
||||||
-- | not in a transaction block
|
-- | not in a transaction block
|
||||||
= TransactionIdle
|
= TransactionIdle
|
||||||
@ -77,28 +79,32 @@ data TransactionStatus
|
|||||||
| TransactionFailed
|
| TransactionFailed
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
-- | Format of query parameters and returned values.
|
||||||
data Format = Text | Binary
|
data Format = Text | Binary
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- All the commands have the same names as presented in the official
|
-- All the commands have the same names as presented in the official
|
||||||
-- postgres documentation except explicit exclusions.
|
-- postgres documentation except explicit exclusions.
|
||||||
--
|
|
||||||
|
-- | Messages that client can issue at the startup phase.
|
||||||
data StartMessage
|
data StartMessage
|
||||||
= StartupMessage Username DatabaseName
|
= StartupMessage !Username !DatabaseName
|
||||||
| SSLRequest
|
| SSLRequest
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
-- | Server responses to startup messages.
|
||||||
data AuthResponse
|
data AuthResponse
|
||||||
= AuthenticationOk
|
= AuthenticationOk
|
||||||
| AuthenticationCleartextPassword
|
| AuthenticationCleartextPassword
|
||||||
| AuthenticationMD5Password MD5Salt
|
| AuthenticationMD5Password !MD5Salt
|
||||||
| AuthenticationGSS
|
| AuthenticationGSS
|
||||||
| AuthenticationSSPI
|
| AuthenticationSSPI
|
||||||
| AuthenticationGSSContinue ByteString
|
| AuthenticationGSSContinue !ByteString
|
||||||
-- same as ErrorResponse
|
-- same as ErrorResponse
|
||||||
| AuthErrorResponse ErrorDesc
|
| AuthErrorResponse !ErrorDesc
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
-- | Messages that client can issue in usual query phase.
|
||||||
data ClientMessage
|
data ClientMessage
|
||||||
= Bind !PortalName !StatementName
|
= Bind !PortalName !StatementName
|
||||||
!Format -- parameter format code, one format for all
|
!Format -- parameter format code, one format for all
|
||||||
@ -123,54 +129,58 @@ data ClientMessage
|
|||||||
| Terminate
|
| Terminate
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data CancelRequest = CancelRequest ServerProcessId ServerSecretKey
|
-- | Message for canceling requests.
|
||||||
|
data CancelRequest = CancelRequest !ServerProcessId !ServerSecretKey
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
-- | All possible responses from a server in usual query phase.
|
||||||
data ServerMessage
|
data ServerMessage
|
||||||
= BackendKeyData ServerProcessId ServerSecretKey
|
= BackendKeyData !ServerProcessId !ServerSecretKey
|
||||||
| BindComplete
|
| BindComplete
|
||||||
| CloseComplete
|
| CloseComplete
|
||||||
| CommandComplete CommandResult
|
| CommandComplete CommandResult
|
||||||
| DataRow (Vector (Maybe ByteString)) -- Nothing shoulde be recognized as NULL
|
| DataRow !(Vector (Maybe ByteString)) -- Nothing shoulde be recognized as NULL
|
||||||
| EmptyQueryResponse
|
| EmptyQueryResponse
|
||||||
| ErrorResponse ErrorDesc
|
| ErrorResponse !ErrorDesc
|
||||||
| NoData
|
| NoData
|
||||||
| NoticeResponse NoticeDesc
|
| NoticeResponse NoticeDesc
|
||||||
| NotificationResponse Notification
|
| NotificationResponse !Notification
|
||||||
| ParameterDescription (Vector Oid)
|
| ParameterDescription !(Vector Oid)
|
||||||
| ParameterStatus ByteString ByteString -- name and value
|
| ParameterStatus !ByteString !ByteString -- name and value
|
||||||
| ParseComplete
|
| ParseComplete
|
||||||
| PortalSuspended
|
| PortalSuspended
|
||||||
| ReadForQuery TransactionStatus
|
| ReadForQuery !TransactionStatus
|
||||||
| RowDescription (Vector FieldDescription)
|
| RowDescription !(Vector FieldDescription)
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
-- | Notification issued by `NOTIFY`.
|
||||||
data Notification = Notification
|
data Notification = Notification
|
||||||
{ notificationProcessId :: ServerProcessId
|
{ notificationProcessId :: !ServerProcessId
|
||||||
, notificationChannel :: ChannelName
|
, notificationChannel :: !ChannelName
|
||||||
, notificationPayload :: ByteString
|
, notificationPayload :: !ByteString
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
-- | Field description returned on describe statement message.
|
||||||
data FieldDescription = FieldDescription {
|
data FieldDescription = FieldDescription {
|
||||||
-- | the field name
|
-- | the field name
|
||||||
fieldName :: ByteString
|
fieldName :: !ByteString
|
||||||
-- | If the field can be identified as a column of a specific table,
|
-- | If the field can be identified as a column of a specific table,
|
||||||
-- the object ID of the table; otherwise zero.
|
-- the object ID of the table; otherwise zero.
|
||||||
, fieldTableOid :: Oid
|
, fieldTableOid :: !Oid
|
||||||
-- | If the field can be identified as a column of a specific table,
|
-- | If the field can be identified as a column of a specific table,
|
||||||
-- the attribute number of the column; otherwise zero.
|
-- the attribute number of the column; otherwise zero.
|
||||||
, fieldColumnNumber :: Int16
|
, fieldColumnNumber :: !Int16
|
||||||
-- | The object ID of the field's data type.
|
-- | The object ID of the field's data type.
|
||||||
, fieldTypeOid :: Oid
|
, fieldTypeOid :: !Oid
|
||||||
-- | The data type size (see pg_type.typlen). Note that negative
|
-- | The data type size (see pg_type.typlen). Note that negative
|
||||||
-- values denote variable-width types.
|
-- values denote variable-width types.
|
||||||
, fieldSize :: Int16
|
, fieldSize :: !Int16
|
||||||
-- | The type modifier (see pg_attribute.atttypmod).
|
-- | The type modifier (see pg_attribute.atttypmod).
|
||||||
, fieldMode :: Int32
|
, fieldMode :: !Int32
|
||||||
-- | The format code being used for the field. In a RowDescription
|
-- | The format code being used for the field. In a RowDescription
|
||||||
-- returned from the statement variant of Describe, the format code
|
-- returned from the statement variant of Describe, the format code
|
||||||
-- is not yet known and will always be zero.
|
-- is not yet known and will always be zero.
|
||||||
, fieldFormat :: Format
|
, fieldFormat :: !Format
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
data ErrorSeverity
|
data ErrorSeverity
|
||||||
@ -189,43 +199,45 @@ data NoticeSeverity
|
|||||||
| UnknownNoticeSeverity
|
| UnknownNoticeSeverity
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
-- | Information about ErrorResponse.
|
||||||
data ErrorDesc = ErrorDesc
|
data ErrorDesc = ErrorDesc
|
||||||
{ errorSeverity :: ErrorSeverity
|
{ errorSeverity :: !ErrorSeverity
|
||||||
, errorCode :: ByteString
|
, errorCode :: !ByteString
|
||||||
, errorMessage :: ByteString
|
, errorMessage :: !ByteString
|
||||||
, errorDetail :: Maybe ByteString
|
, errorDetail :: !Maybe ByteString
|
||||||
, errorHint :: Maybe ByteString
|
, errorHint :: !Maybe ByteString
|
||||||
, errorPosition :: Maybe Int
|
, errorPosition :: !Maybe Int
|
||||||
, errorInternalPosition :: Maybe Int
|
, errorInternalPosition :: !Maybe Int
|
||||||
, errorInternalQuery :: Maybe ByteString
|
, errorInternalQuery :: !Maybe ByteString
|
||||||
, errorContext :: Maybe ByteString
|
, errorContext :: !Maybe ByteString
|
||||||
, errorSchema :: Maybe ByteString
|
, errorSchema :: !Maybe ByteString
|
||||||
, errorTable :: Maybe ByteString
|
, errorTable :: !Maybe ByteString
|
||||||
, errorColumn :: Maybe ByteString
|
, errorColumn :: !Maybe ByteString
|
||||||
, errorDataType :: Maybe ByteString
|
, errorDataType :: !Maybe ByteString
|
||||||
, errorConstraint :: Maybe ByteString
|
, errorConstraint :: !Maybe ByteString
|
||||||
, errorSourceFilename :: Maybe ByteString
|
, errorSourceFilename :: !Maybe ByteString
|
||||||
, errorSourceLine :: Maybe Int
|
, errorSourceLine :: !Maybe Int
|
||||||
, errorSourceRoutine :: Maybe ByteString
|
, errorSourceRoutine :: !Maybe ByteString
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
-- | Information about NoticeResponse.
|
||||||
data NoticeDesc = NoticeDesc
|
data NoticeDesc = NoticeDesc
|
||||||
{ noticeSeverity :: NoticeSeverity
|
{ noticeSeverity :: !NoticeSeverity
|
||||||
, noticeCode :: ByteString
|
, noticeCode :: !ByteString
|
||||||
, noticeMessage :: ByteString
|
, noticeMessage :: !ByteString
|
||||||
, noticeDetail :: Maybe ByteString
|
, noticeDetail :: !Maybe ByteString
|
||||||
, noticeHint :: Maybe ByteString
|
, noticeHint :: !Maybe ByteString
|
||||||
, noticePosition :: Maybe Int
|
, noticePosition :: !Maybe Int
|
||||||
, noticeInternalPosition :: Maybe Int
|
, noticeInternalPosition :: !Maybe Int
|
||||||
, noticeInternalQuery :: Maybe ByteString
|
, noticeInternalQuery :: !Maybe ByteString
|
||||||
, noticeContext :: Maybe ByteString
|
, noticeContext :: !Maybe ByteString
|
||||||
, noticeSchema :: Maybe ByteString
|
, noticeSchema :: !Maybe ByteString
|
||||||
, noticeTable :: Maybe ByteString
|
, noticeTable :: !Maybe ByteString
|
||||||
, noticeColumn :: Maybe ByteString
|
, noticeColumn :: !Maybe ByteString
|
||||||
, noticeDataType :: Maybe ByteString
|
, noticeDataType :: !Maybe ByteString
|
||||||
, noticeConstraint :: Maybe ByteString
|
, noticeConstraint :: !Maybe ByteString
|
||||||
, noticeSourceFilename :: Maybe ByteString
|
, noticeSourceFilename :: !Maybe ByteString
|
||||||
, noticeSourceLine :: Maybe Int
|
, noticeSourceLine :: !Maybe Int
|
||||||
, noticeSourceRoutine :: Maybe ByteString
|
, noticeSourceRoutine :: !Maybe ByteString
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user