Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Table instance for Solo #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rel8.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ source-repository head
library
build-depends:
aeson
, base ^>= 4.14 || ^>=4.15 || ^>=4.16
, base ^>=4.15 || ^>=4.16
, bifunctors
, bytestring
, case-insensitive
Expand Down
13 changes: 13 additions & 0 deletions src/Rel8/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ where
-- base
import Data.Functor.Identity ( Identity( Identity ) )
import Data.Kind ( Constraint, Type )
import Data.Tuple ( Solo( Solo ) )
import GHC.Generics ( Generic, Rep, from, to )
import Prelude hiding ( null )

Expand Down Expand Up @@ -181,6 +182,18 @@ type instance Eval (TSerialize expr a) =
)


instance Table context a => Table context (Solo a) where
type Columns (Solo a) = Columns a
type Context (Solo a) = Context a
type FromExprs (Solo a) = Solo (FromExprs a)
type Transpose to (Solo a) = Solo (Transpose to a)

toColumns (Solo a) = toColumns a
fromColumns = Solo . fromColumns
toResult (Solo a) = toResult @_ @a a
fromResult = Solo . fromResult @_ @a


instance (Table context a, Table context b) => Table context (a, b)


Expand Down
5 changes: 5 additions & 0 deletions src/Rel8/Table/Eq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Data.Foldable ( foldl' )
import Data.Functor.Const ( Const( Const ), getConst )
import Data.Kind ( Constraint, Type )
import Data.List.NonEmpty ( NonEmpty( (:|) ) )
import Data.Tuple ( Solo )
import GHC.Generics ( Rep )
import Prelude

Expand Down Expand Up @@ -66,6 +67,10 @@ instance Sql DBEq a => EqTable (Expr a) where
eqTable = HIdentity Dict


instance EqTable a => EqTable (Solo a) where
eqTable = eqTable @a


instance (EqTable a, EqTable b) => EqTable (a, b)


Expand Down
5 changes: 5 additions & 0 deletions src/Rel8/Table/Ord.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ where
-- base
import Data.Functor.Const ( Const( Const ), getConst )
import Data.Kind ( Constraint, Type )
import Data.Tuple ( Solo )
import GHC.Generics ( Rep )
import Prelude hiding ( seq )

Expand Down Expand Up @@ -66,6 +67,10 @@ instance Sql DBOrd a => OrdTable (Expr a) where
ordTable = HIdentity Dict


instance OrdTable a => OrdTable (Solo a) where
ordTable = ordTable @a


instance (OrdTable a, OrdTable b) => OrdTable (a, b)


Expand Down
4 changes: 4 additions & 0 deletions src/Rel8/Table/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ where
import Data.Functor.Identity ( Identity( Identity ) )
import Data.Kind ( Constraint, Type )
import Data.List.NonEmpty ( NonEmpty )
import Data.Tuple (Solo)
import Prelude

-- hasql
Expand Down Expand Up @@ -57,6 +58,9 @@ instance (Sql DBType a, NotNull a, x ~ Maybe a) => ToExprs (Expr x) (Maybe a)
instance (Sql DBType a, NotNull a, x ~ NonEmpty a) => ToExprs (Expr x) (NonEmpty a)


instance (ToExprs exprs a, x ~ Solo exprs) => ToExprs x (Solo a)


instance (ToExprs exprs1 a, ToExprs exprs2 b, x ~ (exprs1, exprs2)) =>
ToExprs x (a, b)

Expand Down