* Explode the From GADT. Move runFrom into the ToFrom typeclass removing the need for the intermediate structure. Extract the parts of the Experimental module into submodules. * Reorganize Experimental folder. Move Subquery into core Experimental.From module. * Cleanup hackage documentation. Make sure stylish ran correctly. Update changelog and bump version * Update ERaw to change the direction of NeedParens (parent now tells child context). Removed need for composite key constructor * Get rid of AliasedValue and ValueReference; added sqlExprMetaAlias to SqlExprMeta * Remove EList and EEmptyList; ERaw is now technically possible in each case since it is generalized to all * Remove entity specific constructors from SqlExpr * Remove EOrderBy, EDistinctOn; Change PreprocessedFrom a to just be an independent datatype * Remove EOrderByRandom, calling distinctOnOrderBy with rand will choke the db but you shouldnt be using rand anyway. distinctOnOrderBy seems dangerous though * Remove ESet * Remove EInsert and EInsertFinal * Make postgres tests pass * Change aliased val to be legal value by waiting until expr materialization in select clause before adding AS <alias> * Cleanup ToAliasRefernce; Add isReference meta to value reference even though that info isnt currently used anywhere * Expose Experimental submodules * Update changelog * Create a FromRaw to replace FromSubquery and FromIdent in from clause. Modify Experimental to only use FromRaw. * Convert all of experimental to use new From type instead of From type class. Make the data constructors second class, functions should be used. Introduce *Lateral functions, using the same type for lateral and non lateral queries was probably a mistake. * Expose the new functions and fix the mysql test compilation error (type inference was wonky with `Union` replaced with `union_` * Bump version and add more comments * ValidOnClause was too restrictive, ToFrom is actually the correct amount of leniency. ValidOnClause would not catch use of on for a cross join but would prevent nested joins * Unbreak lateral joins by introducing a completely different ValidOnClause constraint * Fixe error introduced in merge with master * Dont realias alias references * Never realias an already aliased Entity or Value * reindex value references to the latest 'source'
80 lines
2.6 KiB
Haskell
80 lines
2.6 KiB
Haskell
{-# LANGUAGE FlexibleInstances #-}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
module Database.Esqueleto.Experimental.ToMaybe
|
|
where
|
|
|
|
import Database.Esqueleto.Internal.Internal hiding (From(..), from, on)
|
|
import Database.Esqueleto.Internal.PersistentImport (Entity(..))
|
|
|
|
type family Nullable a where
|
|
Nullable (Maybe a) = a
|
|
Nullable a = a
|
|
|
|
class ToMaybe a where
|
|
type ToMaybeT a
|
|
toMaybe :: a -> ToMaybeT a
|
|
|
|
instance ToMaybe (SqlExpr (Maybe a)) where
|
|
type ToMaybeT (SqlExpr (Maybe a)) = SqlExpr (Maybe a)
|
|
toMaybe = id
|
|
|
|
instance ToMaybe (SqlExpr (Entity a)) where
|
|
type ToMaybeT (SqlExpr (Entity a)) = SqlExpr (Maybe (Entity a))
|
|
toMaybe (ERaw f m) = (ERaw f m)
|
|
|
|
instance ToMaybe (SqlExpr (Value a)) where
|
|
type ToMaybeT (SqlExpr (Value a)) = SqlExpr (Value (Maybe (Nullable a)))
|
|
toMaybe = veryUnsafeCoerceSqlExprValue
|
|
|
|
|
|
instance (ToMaybe a, ToMaybe b) => ToMaybe (a,b) where
|
|
type ToMaybeT (a, b) = (ToMaybeT a, ToMaybeT b)
|
|
toMaybe (a, b) = (toMaybe a, toMaybe b)
|
|
|
|
instance ( ToMaybe a , ToMaybe b , ToMaybe c) => ToMaybe (a,b,c) where
|
|
type ToMaybeT (a, b, c) = (ToMaybeT a, ToMaybeT b, ToMaybeT c)
|
|
toMaybe = to3 . toMaybe . from3
|
|
|
|
instance ( ToMaybe a , ToMaybe b , ToMaybe c , ToMaybe d) => ToMaybe (a,b,c,d) where
|
|
type ToMaybeT (a, b, c, d) = (ToMaybeT a, ToMaybeT b, ToMaybeT c, ToMaybeT d)
|
|
toMaybe = to4 . toMaybe . from4
|
|
|
|
instance ( ToMaybe a , ToMaybe b , ToMaybe c , ToMaybe d , ToMaybe e) => ToMaybe (a,b,c,d,e) where
|
|
type ToMaybeT (a, b, c, d, e) = (ToMaybeT a, ToMaybeT b, ToMaybeT c, ToMaybeT d, ToMaybeT e)
|
|
toMaybe = to5 . toMaybe . from5
|
|
|
|
instance ( ToMaybe a
|
|
, ToMaybe b
|
|
, ToMaybe c
|
|
, ToMaybe d
|
|
, ToMaybe e
|
|
, ToMaybe f
|
|
) => ToMaybe (a,b,c,d,e,f) where
|
|
type ToMaybeT (a, b, c, d, e, f) = (ToMaybeT a, ToMaybeT b, ToMaybeT c, ToMaybeT d, ToMaybeT e, ToMaybeT f)
|
|
toMaybe = to6 . toMaybe . from6
|
|
|
|
instance ( ToMaybe a
|
|
, ToMaybe b
|
|
, ToMaybe c
|
|
, ToMaybe d
|
|
, ToMaybe e
|
|
, ToMaybe f
|
|
, ToMaybe g
|
|
) => ToMaybe (a,b,c,d,e,f,g) where
|
|
type ToMaybeT (a, b, c, d, e, f, g) = (ToMaybeT a, ToMaybeT b, ToMaybeT c, ToMaybeT d, ToMaybeT e, ToMaybeT f, ToMaybeT g)
|
|
toMaybe = to7 . toMaybe . from7
|
|
|
|
instance ( ToMaybe a
|
|
, ToMaybe b
|
|
, ToMaybe c
|
|
, ToMaybe d
|
|
, ToMaybe e
|
|
, ToMaybe f
|
|
, ToMaybe g
|
|
, ToMaybe h
|
|
) => ToMaybe (a,b,c,d,e,f,g,h) where
|
|
type ToMaybeT (a, b, c, d, e, f, g, h) = (ToMaybeT a, ToMaybeT b, ToMaybeT c, ToMaybeT d, ToMaybeT e, ToMaybeT f, ToMaybeT g, ToMaybeT h)
|
|
toMaybe = to8 . toMaybe . from8
|
|
|