1{-# language FlexibleContexts #-}
2{-# language FlexibleInstances #-}
3{-# language StandaloneKindSignatures #-}
4{-# language UndecidableInstances #-}
12import Data.Aeson ( Value )
15import Data.List.NonEmpty ( NonEmpty )
16import Data.Int ( Int16, Int32, Int64 )
17import Data.Kind ( Constraint, Type )
21import Data.ByteString ( ByteString )
22import qualified Data.ByteString.Lazy as Lazy ( ByteString )
25import Data.CaseInsensitive ( CI )
28import Rel8.Opaque ( Opaque )
29import Rel8.Schema.Nullability ( Sql )
30import Rel8.Type ( DBType )
33import Data.Scientific ( Scientific )
36import Data.Text ( Text )
37import qualified Data.Text.Lazy as Lazy ( Text )
40import Data.Time.Calendar ( Day )
41import Data.Time.Clock ( UTCTime, DiffTime, NominalDiffTime )
42import Data.Time.LocalTime ( TimeOfDay, LocalTime )
45import Data.UUID ( UUID )
48-- | Database types that can be compared for equality in queries. If a type is
49-- an instance of 'DBEq', it means we can compare expressions for equality
50-- using the SQL @=@ operator.
52-- [ @DBEq@ with @newtype@s ]
54-- Like with 'Rel8.DBType', @DBEq@ plays well with generalized newtype
55-- deriving. The example given for @DBType@ added a @UserId@ @newtype@, but
56-- without a @DBEq@ instance won't actually be able to use that in joins or
57-- where-clauses, because it lacks equality. We can add this by changing our
58-- @newtype@ definition to:
60-- >>> newtype UserId = UserId { toInt32 :: Int32 } deriving newtype (DBType, DBEq)
62-- This will re-use the equality logic for @Int32@, which is to just use the
65-- [ @DBEq@ with @DeriveAnyType@ ]
67-- You can also use @DBEq@ with the @DeriveAnyType@ extension to easily add
68-- equality to your type, assuming that @=@ is sufficient on @DBType@ encoded
69-- values. Extending the example from 'Rel8.ReadShow''s 'Rel8.DBType' instance,
70-- we could add equality to @Color@ by writing:
73-- data Color = Red | Green | Blue | Purple | Gold
74-- deriving (Generic, Show, Read, DBEq)
75-- deriving DBType via ReadShow Color
78-- This means @Color@s will be treated as the literal strings @"Red"@,
79-- @"Green"@, etc, in the database, and they can be compared for equality by
81type DBEq :: Type -> Constraint
82class DBType a => DBEq a
92instance DBEq Scientific
95instance DBEq LocalTime
96instance DBEq TimeOfDay
98instance DBEq NominalDiffTime
100instance DBEq Lazy.Text
101instance DBEq (CI Text)
102instance DBEq (CI Lazy.Text)
103instance DBEq ByteString
104instance DBEq Lazy.ByteString
107instance Sql DBEq a => DBEq [a]
108instance Sql DBEq a => DBEq (NonEmpty a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list