k0001 / tisch

Type-safe SQL interactions with PostgreSQL, based on Opaleye.
Apache License 2.0
54 stars 15 forks source link

Add support for built-in range types #32

Open nmdanny opened 7 years ago

nmdanny commented 7 years ago

Tisch doesn't seem to have support for range types

I'm not versed in Tisch's internals, but adding the following code:

import           Data.Time               (Day, LocalTime, UTCTime)
import           Opaleye.PGTypes         (PGRange)
import           Tisch.Internal.Kol      (PgPrimType (..))

instance PgTyped (PGRange PGTimestamptz) where type PgType (PGRange PGTimestamptz) = PGRange PGTimestamptz
instance PgTyped (PGRange PGTimestamp) where type PgType (PGRange PGTimestamp) = PGRange PGTimestamp
instance PgTyped (PGRange (PGNumeric s)) where type PgType (PGRange (PGNumeric s)) = PGRange (PGNumeric s)
instance PgTyped (PGRange PGInt4) where type PgType (PGRange PGInt4) = PGRange PGInt4
instance PgTyped (PGRange PGInt8) where type PgType (PGRange PGInt8) = PGRange PGInt8
instance PgTyped (PGRange PGDate) where type PgType (PGRange PGDate) = PGRange PGDate

instance PgPrimType (PGRange PGTimestamptz) where pgPrimTypeName _ = "tstzrange"
instance PgPrimType (PGRange PGTimestamp) where pgPrimTypeName _ = "tsrange"
instance PgPrimType (PGRange (PGNumeric s)) where pgPrimTypeName _ = "numrange"
instance PgPrimType (PGRange PGInt4) where pgPrimTypeName _ = "int4range"
instance PgPrimType (PGRange PGInt8) where pgPrimTypeName _ = "int8range"
instance PgPrimType (PGRange PGDate) where pgPrimTypeName _ = "daterange"

seems to make the following column compile:

'Column "duration" 'WD 'RN (PGRange PGTimestamptz) (PGRange UTCTime)

(still haven't tested the above code)

k0001 commented 7 years ago

Hey, thanks for this. It looks about right :) I'll try and make the change soon.