napkin-0.5.14
Copyright(c) Soostone Inc 2020
LicenseAllRightsReserved
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Napkin.Untyped.Monad

Description

 
Synopsis

Documentation

data RefStore #

Supply of fresh reference names to be used in monadic contexts where you need an infinite-ish supply.

Instances

Instances details
Data RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

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 #

Generic RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

Associated Types

type Rep RefStore :: Type -> Type #

Methods

from :: RefStore -> Rep RefStore x #

to :: Rep RefStore x -> RefStore #

Show RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

Eq RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

Ord RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

HasRefStore RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

type Rep RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

type Rep RefStore = D1 ('MetaData "RefStore" "Napkin.Untyped.Monad" "napkin-0.5.14-JrXUGmKUOt9J0meJSj0Kh4" '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))))

class HasRefStore s where #

Methods

refRepo :: Lens' s RefStore #

Instances

Instances details
HasRefStore QState # 
Instance details

Defined in Napkin.Untyped.Monad

HasRefStore RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

HasRefStore UState # 
Instance details

Defined in Napkin.Untyped.Monad

HasRefStore SubQueryTransformState # 
Instance details

Defined in Napkin.Untyped.Ops.BigQuery

newRef :: (HasRefStore s, MonadState s m) => m (Ref a) #

data QState #

Constructors

QState 

Instances

Instances details
Data QState # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

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 # 
Instance details

Defined in Napkin.Untyped.Monad

Eq QState # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

(==) :: QState -> QState -> Bool #

(/=) :: QState -> QState -> Bool #

HasRefStore QState # 
Instance details

Defined in Napkin.Untyped.Monad

MonadState QState Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

get :: Q QState #

put :: QState -> Q () #

state :: (QState -> (a, QState)) -> Q a #

newtype Q a #

Constructors

Q 

Fields

Instances

Instances details
Applicative Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

pure :: a -> Q a #

(<*>) :: Q (a -> b) -> Q a -> Q b #

liftA2 :: (a -> b -> c) -> Q a -> Q b -> Q c #

(*>) :: Q a -> Q b -> Q b #

(<*) :: Q a -> Q b -> Q a #

Functor Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

fmap :: (a -> b) -> Q a -> Q b #

(<$) :: a -> Q b -> Q a #

Monad Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

(>>=) :: Q a -> (a -> Q b) -> Q b #

(>>) :: Q a -> Q b -> Q b #

return :: a -> Q a #

MonadState QState Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

get :: Q QState #

put :: QState -> Q () #

state :: (QState -> (a, QState)) -> Q a #

AsRelation (Q a) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

asRelation :: Q a -> Relation #

HasDefinition (Q ()) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

defQuery :: Lens (Q ()) (Q ()) Query Query #

MaybeQuery (Q ()) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

getQuery :: Q () -> Maybe Query #

RenderSql Query backend => RenderSql (Q a) backend #

Monadic query interface

Instance details

Defined in Napkin.Render.Types

Methods

renderSql :: backend -> Q a -> Doc #

runQ :: Q a -> (a, Query) #

mkQ :: Q a -> Query #

evalQ :: Q c -> c #

modQ :: Query -> Q a -> Query #

Alter a pre-existing Query monadically.

asQuery :: Iso' (Q ()) Query #

withQ_ :: Q a -> Q (Ref Relation) #

Define a subquery using the WITH syntax. Note that this does not automatically include this table in a SELECT; you need to additionally include the resulting relation from withQ_ using the from_ operator.

withQAs_ :: Ref Query -> Q a -> Q (Ref Table) #

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.

selectAs_' :: Alias SExp -> Q (Maybe (Ref SExp)) #

Add optional aliasing to the Q.

annotateJson :: ToJSON a => a -> Ref SExp -> Q (Ref SExp) #

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.

fromRel :: AsRelation r => r -> Q (Ref Relation) #

fromSpecified :: Q Bool #

Returns True iff the current Query already has an initial From table available.

having :: MonadState QState m => SExp -> m () #

havingL :: Applicative f => (Maybe SExp -> f (Maybe SExp)) -> QState -> f QState #

where_ :: SExp -> Q () #

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

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 #

Turn query into relation

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 Queryies, 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.

explicitSelectStarWith #

Arguments

:: s

Object containing definitions

-> Ref Relation

Concrete reference within the context

-> Getting (Endo [Ref SExp]) s (Ref SExp)

Traversal to get field definitions from the object

-> (Selected SExp -> Selected SExp)

A function to modify the final selection

-> Q () 

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.

explicitMapSelectStar :: HasDefinition s => s -> Ref Relation -> (Selected SExp -> Selected SExp) -> 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.

selectStar :: Ref Relation -> Q (Ref Relation) #

select * from x

selectNonDuplicates :: Foldable t => t (Ref SExp) -> Q () #

Given a list of references, select those that have not yet been selected in current monadic block.

mapSelectNonDuplicates :: Foldable t => t (Ref SExp) -> (Selected SExp -> Selected SExp) -> Q () #

Given a list of references, select those that have not yet been selected in current monadic block with option to modify the finalized selection.

data UState #

Constructors

UState 

Instances

Instances details
Data UState # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UState -> c UState #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UState #

toConstr :: UState -> Constr #

dataTypeOf :: UState -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UState) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UState) #

gmapT :: (forall b. Data b => b -> b) -> UState -> UState #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UState -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UState -> r #

gmapQ :: (forall d. Data d => d -> u) -> UState -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> UState -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> UState -> m UState #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UState -> m UState #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UState -> m UState #

Show UState # 
Instance details

Defined in Napkin.Untyped.Monad

Eq UState # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

(==) :: UState -> UState -> Bool #

(/=) :: UState -> UState -> Bool #

HasRefStore UState # 
Instance details

Defined in Napkin.Untyped.Monad

MonadState UState U # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

get :: U UState #

put :: UState -> U () #

state :: (UState -> (a, UState)) -> U a #

newtype U a #

Constructors

U 

Fields

Instances

Instances details
Applicative U # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

pure :: a -> U a #

(<*>) :: U (a -> b) -> U a -> U b #

liftA2 :: (a -> b -> c) -> U a -> U b -> U c #

(*>) :: U a -> U b -> U b #

(<*) :: U a -> U b -> U a #

Functor U # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

fmap :: (a -> b) -> U a -> U b #

(<$) :: a -> U b -> U a #

Monad U # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

(>>=) :: U a -> (a -> U b) -> U b #

(>>) :: U a -> U b -> U b #

return :: a -> U a #

MonadState UState U # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

get :: U UState #

put :: UState -> U () #

state :: (UState -> (a, UState)) -> U a #

updateSet_ :: Name -> SExp -> U () #