1{-# language FlexibleContexts #-}
2{-# language FlexibleInstances #-}
3{-# language MultiParamTypeClasses #-}
4{-# language StandaloneKindSignatures #-}
5{-# language UndecidableInstances #-}
13import Data.Aeson ( Value )
16import Data.List.NonEmpty ( NonEmpty )
17import Data.Int ( Int16, Int32, Int64 )
18import Data.Kind ( Constraint, Type )
22import Data.ByteString ( ByteString )
23import qualified Data.ByteString.Lazy as Lazy ( ByteString )
26import Data.CaseInsensitive ( CI )
29import Rel8.Opaque ( Opaque )
30import Rel8.Schema.Nullability ( Unnullify, HasNullability, Sql )
31import Rel8.Type ( DBType )
34import Data.Scientific ( Scientific )
37import Data.Text ( Text )
38import qualified Data.Text.Lazy as Lazy ( Text )
41import Data.Time.Calendar ( Day )
42import Data.Time.Clock ( UTCTime, DiffTime, NominalDiffTime )
43import Data.Time.LocalTime ( TimeOfDay, LocalTime )
46import Data.UUID ( UUID )
49-- | Database types that can be compared for equality in queries. If a type is
50-- an instance of 'DBEq', it means we can compare expressions for equality
51-- using the SQL @=@ operator.
53-- [ @DBEq@ with @newtype@s ]
55-- Like with 'Rel8.DBType', @DBEq@ plays well with generalized newtype
56-- deriving. The example given for @DBType@ added a @UserId@ @newtype@, but
57-- without a @DBEq@ instance won't actually be able to use that in joins or
58-- where-clauses, because it lacks equality. We can add this by changing our
59-- @newtype@ definition to:
61-- >>> newtype UserId = UserId { toInt32 :: Int32 } deriving newtype (DBType, DBEq)
63-- This will re-use the equality logic for @Int32@, which is to just use the
66-- [ @DBEq@ with @DeriveAnyType@ ]
68-- You can also use @DBEq@ with the @DeriveAnyType@ extension to easily add
69-- equality to your type, assuming that @=@ is sufficient on @DBType@ encoded
70-- values. Extending the example from 'Rel8.ReadShow''s 'Rel8.DBType' instance,
71-- we could add equality to @Color@ by writing:
74-- data Color = Red | Green | Blue | Purple | Gold
75-- deriving (Generic, Show, Read, DBEq)
76-- deriving DBType via ReadShow Color
79-- This means @Color@s will be treated as the literal strings @"Red"@,
80-- @"Green"@, etc, in the database, and they can be compared for equality by
82type DBEq :: Type -> Constraint
83class DBType a => DBEq a
93instance DBEq Scientific
96instance DBEq LocalTime
97instance DBEq TimeOfDay
99instance DBEq NominalDiffTime
101instance DBEq Lazy.Text
102instance DBEq (CI Text)
103instance DBEq (CI Lazy.Text)
104instance DBEq ByteString
105instance DBEq Lazy.ByteString
108instance Sql DBEq a => DBEq [a]
109instance Sql DBEq a => DBEq (NonEmpty a)
113instance {-# INCOHERENT #-} (HasNullability a, DBEq (Unnullify 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