napkin-0.5.11
Copyright(c) Soostone Inc 2020
LicenseAllRightsReserved
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

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

Defined in Napkin.Untyped.Monad

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 #

Ord RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

Show RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

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 #

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.11-AmFJpcsQ4Ny8ZeMMGxUvw7" '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 RefStore # 
Instance details

Defined in Napkin.Untyped.Monad

HasRefStore QState # 
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
Eq QState # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

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

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

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

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

Functor Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

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

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

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 #

MonadState QState Q # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

get :: Q QState #

put :: QState -> Q () #

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

MaybeQuery (Q ()) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

getQuery :: Q () -> Maybe Query #

HasDefinition (Q ()) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

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

AsRelation (Q a) # 
Instance details

Defined in Napkin.Untyped.Monad

Methods

asRelation :: Q a -> Relation #

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.

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) 
-> 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.

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.