Movatterモバイル変換


[0]ホーム

URL:


modulePostgreSQLBinary.DecoderwhereimportPostgreSQLBinary.Preludehiding(bool)importqualifiedData.ByteStringasBimportqualifiedData.ByteString.Lazy.BuilderasBBimportqualifiedData.ByteString.LazyasBLimportqualifiedData.TextasTimportqualifiedData.Text.EncodingasTEimportqualifiedData.Text.LazyasTLimportqualifiedData.Text.Lazy.EncodingasTLEimportqualifiedData.ScientificasScientificimportqualifiedData.UUIDasUUIDimportqualifiedPostgreSQLBinary.Decoder.ZeptoasZeptoimportqualifiedPostgreSQLBinary.ArrayasArrayimportqualifiedPostgreSQLBinary.TimeasTimeimportqualifiedPostgreSQLBinary.IntegralasIntegralimportqualifiedPostgreSQLBinary.NumericasNumericimportqualifiedPostgreSQLBinary.IntervalasInterval-- |-- A function for decoding a byte string into a value.typeDa=ByteString->EitherTexta-- * Numbers--------------------------- |-- Any of PostgreSQL integer types.{-# INLINABLE int #-}int::(Integrala,Bitsa)=>Daint=Right.Integral.pack{-# INLINABLE float4 #-}float4::DFloatfloat4=unsafeCoerce(int::DWord32){-# INLINABLE float8 #-}float8::DDoublefloat8=unsafeCoerce(int::DWord64){-# INLINABLE numeric #-}numeric::DScientificnumeric=flipZepto.run(inlineZepto.numeric)-- * Text--------------------------- |-- A UTF-8-encoded char.{-# INLINABLE char #-}char::DCharcharx=maybe(Left"Empty input")(return.fst).T.uncons=<<textx-- |-- Any of the variable-length character types:-- BPCHAR, VARCHAR, NAME and TEXT.{-# INLINABLE text #-}text::DTexttext=either(Left.fromString.show)Right.TE.decodeUtf8'{-# INLINE bytea #-}bytea::DByteStringbytea=Right-- * Date and Time-------------------------{-# INLINABLE date #-}date::DDaydate=fmap(Time.postgresJulianToDay.fromIntegral).(int::DInt32)-- |-- The decoding strategy depends on whether the server supports @integer_datetimes@.{-# INLINABLE time #-}time::Bool->DTimeOfDaytime=\caseTrue->fmapTime.microsToTimeOfDay.intFalse->fmapTime.secsToTimeOfDay.float8-- |-- The decoding strategy depends on whether the server supports @integer_datetimes@.{-# INLINABLE timetz #-}timetz::Bool->D(TimeOfDay,TimeZone)timetzinteger_datetimes=\x->let(timeX,zoneX)=B.splitAt8xin(,)<$>timeinteger_datetimestimeX<*>tzzoneXwheretz=fmap(minutesToTimeZone.negate.(`div`60).fromIntegral).(int::DInt32)-- |-- The decoding strategy depends on whether the server supports @integer_datetimes@.{-# INLINABLE timestamptz #-}timestamp::Bool->DLocalTimetimestamp=\caseTrue->fmapTime.microsToLocalTime.intFalse->fmapTime.secsToLocalTime.float8-- |-- The decoding strategy depends on whether the server supports @integer_datetimes@.{-# INLINABLE timestamp #-}timestamptz::Bool->DUTCTimetimestamptz=\caseTrue->fmapTime.microsToUTC.intFalse->fmapTime.secsToUTC.float8-- |-- The decoding strategy depends on whether the server supports @integer_datetimes@.{-# INLINABLE interval #-}interval::Bool->DDiffTimeintervalintegerDatetimes=evalState$dot<-state$B.splitAt8d<-state$B.splitAt4m<-getreturn$doux<-ifintegerDatetimestheninttelsefloat8t>>=return.round.(*(10^6)).toRationaldx<-intdmx<-intmreturn$Interval.toDiffTime$Interval.Intervaluxdxmx-- * Misc-------------------------{-# INLINABLE bool #-}bool::DBoolboolb=caseB.unconsbofJust(0,_)->returnFalseJust(1,_)->returnTrue_->Left("Invalid value: "<>(fromString.show)b){-# INLINABLE uuid #-}uuid::DUUIDuuid=evalStateT$UUID.fromWords<$>word<*>word<*>word<*>wordwhereword=lift.int=<<state(B.splitAt4)-- |-- Arbitrary array.---- Returns an intermediate representation,-- which can then be used to decode into a specific data type.{-# INLINABLE array #-}array::DArray.Dataarray=flipZepto.runZepto.array

[8]ページ先頭

©2009-2025 Movatter.jp