Copyright | (c) Soostone Inc 2020 |
---|---|
License | AllRightsReserved |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data RefStore = RefStore {}
- refStore_feed :: Lens' RefStore [String]
- refStore_blacklist :: Lens' RefStore (Set String)
- class HasRefStore s where
- letters :: String
- newRefStore :: RefStore
- newRef :: (HasRefStore s, MonadState s m) => m (Ref a)
- newQState :: QState
- data QState = QState {}
- qsVars :: Lens' QState RefStore
- qsQuery :: Lens' QState Query
- newtype Q a = Q {}
- runQ :: Q a -> (a, Query)
- mkQ :: Q a -> Query
- evalQ :: Q c -> c
- modQ :: Query -> Q a -> Query
- asQuery :: Iso' (Q ()) Query
- with_ :: Query -> Q (Ref Relation)
- withQ_ :: Q a -> Q (Ref Relation)
- withQ'_ :: Q a -> Q (Ref Relation, Query)
- withQAs_ :: Ref Query -> Q a -> Q (Ref Table)
- withAs_ :: Selected Query -> Q (Ref Table)
- withAsUnique :: Selected Query -> Q (Ref Table)
- select_ :: SExp -> Q (Ref SExp)
- selectAs_ :: Selected SExp -> Q (Ref SExp)
- selectsAs_ :: [Selected SExp] -> Q [Ref SExp]
- selectAs_' :: Alias SExp -> Q (Maybe (Ref SExp))
- selectsAs_' :: [Alias SExp] -> Q [Maybe (Ref SExp)]
- selectsGroupsAs_ :: [Selected SExp] -> Q ()
- selectsGroupsAsRef_ :: [Selected SExp] -> Q ()
- selectNonEmptyGroups :: [Selected SExp] -> Q ()
- from_ :: Relation -> Q (Ref Relation)
- fromIfNecessary :: Relation -> Q (Ref Relation)
- fromSelected_ :: Selected Relation -> Q (Ref Relation)
- fromAlias_ :: Alias Relation -> Q (Ref Relation)
- fromRef_ :: Ref Relation -> Q (Ref Relation)
- fromRel :: AsRelation r => r -> Q (Ref Relation)
- fromSpecified :: Q Bool
- fromOrJoin :: Alias Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation)
- join_ :: JoinType -> Relation -> (Ref Relation -> Maybe SExp) -> Q (Ref Relation)
- joinUsing_ :: JoinType -> Relation -> [Ref SExp] -> Q (Ref Relation)
- joinRef_ :: JoinType -> Ref Relation -> (Ref Relation -> Maybe SExp) -> Q (Ref Relation)
- joinSelected_ :: JoinType -> Selected Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation)
- joinAlias_ :: JoinType -> Alias Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation)
- joinOn_ :: JoinType -> Relation -> (Ref Relation -> SExp) -> Q (Ref Relation)
- innerJoin :: Relation -> (Ref Relation -> SExp) -> Q (Ref Relation)
- crossJoin :: Relation -> Q (Ref Relation)
- leftJoin :: Relation -> (Ref Relation -> SExp) -> Q (Ref Relation)
- rightJoin :: Relation -> (Ref Relation -> SExp) -> Q (Ref Relation)
- outerJoin :: Relation -> (Ref Relation -> SExp) -> Q (Ref Relation)
- having :: MonadState QState m => SExp -> m ()
- havingL :: Applicative f => (Maybe SExp -> f (Maybe SExp)) -> QState -> f QState
- where_ :: SExp -> Q ()
- whereL :: (Maybe SExp -> Identity (Maybe SExp)) -> QState -> Identity QState
- whereAdd :: MonadState QState m => SExp -> m ()
- whereAddIn :: MonadState QState m => SExp -> [SExp] -> m ()
- whereAddNotIn :: MonadState QState m => SExp -> [SExp] -> m ()
- groupBy_ :: [SExp] -> Q ()
- orderBy_ :: Order -> Q ()
- limit_ :: MonadState QState m => Int -> m ()
- offset_ :: MonadState QState m => Int -> m ()
- mdef :: a -> Iso' (Maybe a) a
- fromQuery :: Q a -> Relation
- scopeRelation :: SExp -> Relation -> Relation
- selectEverything :: [(Ref Relation, DefinedQuery)] -> Q ()
- explicitSelectStarWith :: s -> Ref Relation -> Getting (Endo [Ref SExp]) s (Ref SExp) -> Q ()
- explicitSelectStar :: HasDefinition s => s -> Ref Relation -> Q ()
- selectStar :: Ref Relation -> Q (Ref Relation)
- selectNonDuplicates :: Foldable t => t (Ref SExp) -> Q ()
- mapSelectNonDuplicates :: Foldable t => t (Ref SExp) -> (Selected SExp -> Selected SExp) -> Q ()
- union_ :: UnionType -> Query -> Query -> WithClauses -> Q ()
Documentation
Supply of fresh reference names to be used in monadic contexts where you need an infinite-ish supply.
Instances
Eq RefStore # | |
Data RefStore # | |
Defined in Napkin.Untyped.Monad gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RefStore -> c RefStore # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RefStore # toConstr :: RefStore -> Constr # dataTypeOf :: RefStore -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c RefStore) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RefStore) # gmapT :: (forall b. Data b => b -> b) -> RefStore -> RefStore # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RefStore -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RefStore -> r # gmapQ :: (forall d. Data d => d -> u) -> RefStore -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> RefStore -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RefStore -> m RefStore # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RefStore -> m RefStore # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RefStore -> m RefStore # | |
Ord RefStore # | |
Defined in Napkin.Untyped.Monad | |
Show RefStore # | |
Generic RefStore # | |
HasRefStore RefStore # | |
type Rep RefStore # | |
Defined in Napkin.Untyped.Monad type Rep RefStore = D1 ('MetaData "RefStore" "Napkin.Untyped.Monad" "napkin-0.5.11-LzNtVzWpCFCrZQk4T3eyK" 'False) (C1 ('MetaCons "RefStore" 'PrefixI 'True) (S1 ('MetaSel ('Just "_refStore_feed") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]) :*: S1 ('MetaSel ('Just "_refStore_blacklist") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set String)))) |
refStore_feed :: Lens' RefStore [String] #
class HasRefStore s where #
Instances
newRefStore :: RefStore #
newRef :: (HasRefStore s, MonadState s m) => m (Ref a) #
Instances
Eq QState # | |
Data QState # | |
Defined in Napkin.Untyped.Monad gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> QState -> c QState # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c QState # toConstr :: QState -> Constr # dataTypeOf :: QState -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c QState) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c QState) # gmapT :: (forall b. Data b => b -> b) -> QState -> QState # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> QState -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> QState -> r # gmapQ :: (forall d. Data d => d -> u) -> QState -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> QState -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> QState -> m QState # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> QState -> m QState # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> QState -> m QState # | |
Show QState # | |
HasRefStore QState # | |
MonadState QState Q # | |
Instances
Monad Q # | |
Functor Q # | |
Applicative Q # | |
MonadState QState Q # | |
MaybeQuery (Q ()) # | |
HasDefinition (Q ()) # | |
AsRelation (Q a) # | |
Defined in Napkin.Untyped.Monad asRelation :: Q a -> Relation # | |
RenderSql Query backend => RenderSql (Q a) backend # | Monadic query interface |
Defined in Napkin.Render.Types |
withAs_ :: Selected Query -> Q (Ref Table) #
Define a WITH subquery while retaining and re-using its given name. Useful in some scenarios where you want to keep the original name in further referring to the newly introduced subquery table.
withAsUnique :: Selected Query -> Q (Ref Table) #
Use unique naming scheme along with Ref Relation to construct the WITH macro's name. This is useful when ensuring unique naming while not throwing out some human-readable information.
select_ :: SExp -> Q (Ref SExp) #
Smart selector that will use the variable's name if expression is a variable and assign a fresh variable name if it's something else without a name.
selectsGroupsAs_ :: [Selected SExp] -> Q () #
Select a field and also include it in GROUP BY. Do this intelligently, referring to it by its given name in most cases but by its direct expression definition in case of external functions to prevent overlap with fields that may already exist.
selectsGroupsAsRef_ :: [Selected SExp] -> Q () #
Like selectsGroupsAs_
but will use the name you gave to each
field in the group by statement. Some backends like BigQuery
require this while others like Redshift don't like it.
selectNonEmptyGroups :: [Selected SExp] -> Q () #
Special convenience case: Select and group while demanding that none of the group values is null.
fromIfNecessary :: Relation -> Q (Ref Relation) #
Add a from clause unless the relation is already in place.
fromRef_ :: Ref Relation -> Q (Ref Relation) #
Use a name directly and don't alias it one more time. | This can fail to create a proper alias if the Ref includes multiple names.
fromSpecified :: Q Bool #
Returns True iff the current Query already has an initial From table available.
fromOrJoin :: Alias Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation) #
joinSelected_ :: JoinType -> Selected Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation) #
joinAlias_ :: JoinType -> Alias Relation -> Either (Ref Relation -> Maybe SExp) [Ref SExp] -> Q (Ref Relation) #
having :: MonadState QState m => SExp -> m () #
whereAdd :: MonadState QState m => SExp -> m () #
whereAddIn :: MonadState QState m => SExp -> [SExp] -> m () #
where x in y
whereAddNotIn :: MonadState QState m => SExp -> [SExp] -> m () #
where x not in y
limit_ :: MonadState QState m => Int -> m () #
offset_ :: MonadState QState m => Int -> m () #
scopeRelation :: SExp -> Relation -> Relation #
Make a query relation that applies predicate on the given relation in a subquery.
selectEverything :: [(Ref Relation, DefinedQuery)] -> Q () #
Introspects the given list of Query
ies, along with their
references in the current context, and selects every named field in
them within the current context, while deduplicating repeat fields
(by name). Good for the common case of joining tables and selecting
everything possible in them.
explicitSelectStar :: HasDefinition s => s -> Ref Relation -> Q () #
Instead of doing a select * that's impossible to introspect, explicitly select all fields from something that contains a definition - e.g. a Query.
selectNonDuplicates :: Foldable t => t (Ref SExp) -> Q () #
Given a list of references, select those that have not yet been selected in current monadic block.