on b2e2fc9 help sign in
rel8/src/Rel8/Schema/Field.hs
695 lines 21 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language GADTs #-}
4{-# language LambdaCase #-}
5{-# language MultiParamTypeClasses #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Schema.Field
11 ( Field
12 , HEither, HList, HMaybe, HNonEmpty, HThese
13 , AField(..)
14 , AHEither(..), AHList(..), AHMaybe(..), AHNonEmpty(..), AHThese(..)
15 )
16where
18-- base
19import Control.Applicative ( liftA2 )
20import Data.Bifunctor ( Bifunctor, bimap )
21import Data.Kind ( Type )
22import Data.List.NonEmpty ( NonEmpty )
23import Prelude
25-- rel8
26import Rel8.Aggregate ( Aggregate, Col(..) )
27import Rel8.Expr ( Expr, Col(..) )
28import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
29import Rel8.Kind.Necessity
30 ( Necessity( Required, Optional )
31 , SNecessity( SRequired, SOptional )
32 , KnownNecessity, necessitySing
33 )
34import Rel8.Schema.Context ( Col(..) )
35import Rel8.Schema.HTable.Either ( HEitherTable )
36import Rel8.Schema.HTable.List ( HListTable )
37import Rel8.Schema.HTable.Maybe ( HMaybeTable )
38import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
39import Rel8.Schema.HTable.These ( HTheseTable )
40import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
41import Rel8.Schema.Insert ( Insert, Col(..) )
42import qualified Rel8.Schema.Kind as K
43import Rel8.Schema.Name ( Name(..), Col(..) )
44import Rel8.Schema.Null ( Sql )
45import Rel8.Schema.Reify ( Reify, Col(..), hreify, hunreify )
46import Rel8.Schema.Result ( Result )
47import Rel8.Schema.Spec ( Spec( Spec ) )
48import Rel8.Table
49 ( Table, Columns, Congruent, Context, fromColumns, toColumns
50 , Unreify, reify, unreify
51 )
52import Rel8.Table.Either ( EitherTable )
53import Rel8.Table.List ( ListTable( ListTable ) )
54import Rel8.Table.Maybe ( MaybeTable )
55import Rel8.Table.NonEmpty ( NonEmptyTable( NonEmptyTable ) )
56import Rel8.Table.Recontextualize ( Recontextualize )
57import Rel8.Table.These ( TheseTable )
58import Rel8.Table.Unreify ( Unreifiable )
59import Rel8.Type ( DBType )
61-- these
62import Data.These ( These )
65type Field :: K.Context -> Necessity -> Type -> Type
66type family Field context necessity a where
67 Field (Reify context) necessity a = AField context necessity a
68 Field Aggregate _necessity a = Aggregate (Expr a)
69 Field Expr _necessity a = Expr a
70 Field Insert 'Required a = Expr a
71 Field Insert 'Optional a = Maybe (Expr a)
72 Field Name _necessity a = Name a
73 Field Result _necessity a = a
76type HEither :: K.Context -> Type -> Type -> Type
77type family HEither context where
78 HEither (Reify context) = AHEither context
79 HEither Aggregate = EitherTable
80 HEither Expr = EitherTable
81 HEither Insert = EitherTable
82 HEither Name = EitherTable
83 HEither Result = Either
86type HList :: K.Context -> Type -> Type
87type family HList context where
88 HList (Reify context) = AHList context
89 HList Aggregate = ListTable
90 HList Expr = ListTable
91 HList Insert = ListTable
92 HList Name = ListTable
93 HList Result = []
96type HMaybe :: K.Context -> Type -> Type
97type family HMaybe context where
98 HMaybe (Reify context) = AHMaybe context
99 HMaybe Aggregate = MaybeTable
100 HMaybe Expr = MaybeTable
101 HMaybe Insert = MaybeTable
102 HMaybe Name = MaybeTable
103 HMaybe Result = Maybe
106type HNonEmpty :: K.Context -> Type -> Type
107type family HNonEmpty context where
108 HNonEmpty (Reify context) = AHNonEmpty context
109 HNonEmpty Aggregate = NonEmptyTable
110 HNonEmpty Expr = NonEmptyTable
111 HNonEmpty Insert = NonEmptyTable
112 HNonEmpty Name = NonEmptyTable
113 HNonEmpty Result = NonEmpty
116type HThese :: K.Context -> Type -> Type -> Type
117type family HThese context where
118 HThese (Reify context) = AHThese context
119 HThese Aggregate = TheseTable
120 HThese Expr = TheseTable
121 HThese Insert = TheseTable
122 HThese Name = TheseTable
123 HThese Result = These
126type AField :: K.Context -> Necessity -> Type -> Type
127newtype AField context necessity a = AField (Field context necessity a)
130instance (Reifiable context, KnownNecessity necessity, Sql DBType a) =>
131 Table (Reify context) (AField context necessity a)
132 where
133 type Context (AField context necessity a) = Reify context
134 type Columns (AField context necessity a) = HIdentity ('Spec '[""] necessity a)
135 type Unreify (AField context necessity a) = Field context necessity a
137 fromColumns (HIdentity (Reify a)) = sfromColumn contextSing a
138 toColumns = HIdentity . Reify . stoColumn contextSing necessitySing
139 reify _ = AField
140 unreify _ (AField a) = a
143instance
144 ( Reifiable context, Reifiable context'
145 , KnownNecessity necessity, Sql DBType a
146 ) =>
147 Recontextualize
148 (Reify context)
149 (Reify context')
150 (AField context necessity a)
151 (AField context' necessity a)
154type AHEither :: K.Context -> Type -> Type -> Type
155newtype AHEither context a b = AHEither (HEither context a b)
158instance Reifiable context => Bifunctor (AHEither context) where
159 bimap = sbimapEither contextSing
162instance Reifiable context => Functor (AHEither context a) where
163 fmap = bimap id
166instance (Reifiable context, Table (Reify context) a, Table (Reify context) b)
167 => Table (Reify context) (AHEither context a b)
168 where
169 type Context (AHEither context a b) = Reify context
170 type Columns (AHEither context a b) = HEitherTable (Columns a) (Columns b)
171 type Unreify (AHEither context a b) = HEither context (Unreify a) (Unreify b)
173 fromColumns = sfromColumnsEither contextSing
174 toColumns = stoColumnsEither contextSing
175 reify proof = liftA2 bimap reify reify proof . AHEither
176 unreify proof = (\(AHEither a) -> a) . liftA2 bimap unreify unreify proof
179instance
180 ( Reifiable context, Reifiable context'
181 , Recontextualize (Reify context) (Reify context') a a'
182 , Recontextualize (Reify context) (Reify context') b b'
183 ) =>
184 Recontextualize
185 (Reify context)
186 (Reify context')
187 (AHEither context a b)
188 (AHEither context' a' b')
191type AHList :: K.Context -> Type -> Type
192newtype AHList context a = AHList (HList context a)
195instance
196 ( Reifiable context
197 , Table (Reify context) a
198 , Unreifiable (Reify context) a
199 )
200 => Table (Reify context) (AHList context a)
201 where
202 type Context (AHList context a) = Reify context
203 type Columns (AHList context a) = HListTable (Columns a)
204 type Unreify (AHList context a) = HList context (Unreify a)
206 fromColumns = sfromColumnsList contextSing
207 toColumns = stoColumnsList contextSing
208 reify proof =
209 smapList contextSing (reify proof) hreify .
210 AHList
211 unreify proof =
212 (\(AHList a) -> a) .
213 smapList contextSing (unreify proof) hunreify
216instance
217 ( Reifiable context, Reifiable context'
218 , Unreifiable (Reify context) a, Unreifiable (Reify context') a'
219 , Recontextualize (Reify context) (Reify context') a a'
220 ) =>
221 Recontextualize
222 (Reify context)
223 (Reify context')
224 (AHList context a)
225 (AHList context' a')
228type AHMaybe :: K.Context -> Type -> Type
229newtype AHMaybe context a = AHMaybe (HMaybe context a)
232instance Reifiable context => Functor (AHMaybe context) where
233 fmap = smapMaybe contextSing
236instance (Reifiable context, Table (Reify context) a) =>
237 Table (Reify context) (AHMaybe context a)
238 where
239 type Context (AHMaybe context a) = Reify context
240 type Columns (AHMaybe context a) = HMaybeTable (Columns a)
241 type Unreify (AHMaybe context a) = HMaybe context (Unreify a)
243 fromColumns = sfromColumnsMaybe contextSing
244 toColumns = stoColumnsMaybe contextSing
245 reify proof = fmap fmap reify proof . AHMaybe
246 unreify proof = (\(AHMaybe a) -> a) . fmap fmap unreify proof
249instance
250 ( Reifiable context, Reifiable context'
251 , Recontextualize (Reify context) (Reify context') a a'
252 ) =>
253 Recontextualize
254 (Reify context)
255 (Reify context')
256 (AHMaybe context a)
257 (AHMaybe context' a')
260type AHNonEmpty :: K.Context -> Type -> Type
261newtype AHNonEmpty context a = AHNonEmpty (HNonEmpty context a)
264instance
265 ( Reifiable context
266 , Table (Reify context) a
267 , Unreifiable (Reify context) a
268 )
269 => Table (Reify context) (AHNonEmpty context a)
270 where
271 type Context (AHNonEmpty context a) = Reify context
272 type Columns (AHNonEmpty context a) = HNonEmptyTable (Columns a)
273 type Unreify (AHNonEmpty context a) = HNonEmpty context (Unreify a)
275 fromColumns = sfromColumnsNonEmpty contextSing
276 toColumns = stoColumnsNonEmpty contextSing
277 reify proof =
278 smapNonEmpty contextSing (reify proof) hreify .
279 AHNonEmpty
280 unreify proof =
281 (\(AHNonEmpty a) -> a) .
282 smapNonEmpty contextSing (unreify proof) hunreify
285instance
286 ( Reifiable context, Reifiable context'
287 , Unreifiable (Reify context) a, Unreifiable (Reify context') a'
288 , Recontextualize (Reify context) (Reify context') a a'
289 ) =>
290 Recontextualize
291 (Reify context)
292 (Reify context')
293 (AHNonEmpty context a)
294 (AHNonEmpty context' a')
297type AHThese :: K.Context -> Type -> Type -> Type
298newtype AHThese context a b = AHThese (HThese context a b)
301instance Reifiable context => Bifunctor (AHThese context) where
302 bimap = sbimapThese contextSing
305instance Reifiable context => Functor (AHThese context a) where
306 fmap = bimap id
309instance (Reifiable context, Table (Reify context) a, Table (Reify context) b)
310 => Table (Reify context) (AHThese context a b)
311 where
312 type Context (AHThese context a b) = Reify context
313 type Columns (AHThese context a b) = HTheseTable (Columns a) (Columns b)
314 type Unreify (AHThese context a b) = HThese context (Unreify a) (Unreify b)
316 fromColumns = sfromColumnsThese contextSing
317 toColumns = stoColumnsThese contextSing
318 reify proof = liftA2 bimap reify reify proof . AHThese
319 unreify proof = (\(AHThese a) -> a) . liftA2 bimap unreify unreify proof
322instance
323 ( Reifiable context, Reifiable context'
324 , Recontextualize (Reify context) (Reify context') a a'
325 , Recontextualize (Reify context) (Reify context') b b'
326 ) =>
327 Recontextualize
328 (Reify context)
329 (Reify context')
330 (AHThese context a b)
331 (AHThese context' a' b')
334sfromColumn :: ()
335 => SContext context
336 -> Col context ('Spec labels necessity a)
337 -> AField context necessity a
338sfromColumn = \case
339 SAggregate -> \(Aggregation a) -> AField a
340 SExpr -> \(DB a) -> AField a
341 SResult -> \(Result a) -> AField a
342 SInsert -> \case
343 RequiredInsert a -> AField a
344 OptionalInsert a -> AField a
345 SName -> \(NameCol a) -> AField (Name a)
346 SReify context -> \(Reify a) -> AField (sfromColumn context a)
349stoColumn :: ()
350 => SContext context
351 -> SNecessity necessity
352 -> AField context necessity a
353 -> Col context ('Spec labels necessity a)
354stoColumn = \case
355 SAggregate -> \_ (AField a) -> Aggregation a
356 SExpr -> \_ (AField a) -> DB a
357 SResult -> \_ (AField a) -> Result a
358 SInsert -> \case
359 SRequired -> \(AField a) -> RequiredInsert a
360 SOptional -> \(AField a) -> OptionalInsert a
361 SName -> \_ (AField (Name a)) -> NameCol a
362 SReify context ->
363 \necessity (AField a) -> Reify (stoColumn context necessity a)
366sbimapEither :: ()
367 => SContext context
368 -> (a -> c)
369 -> (b -> d)
370 -> AHEither context a b
371 -> AHEither context c d
372sbimapEither = \case
373 SAggregate -> \f g (AHEither a) -> AHEither (bimap f g a)
374 SExpr -> \f g (AHEither a) -> AHEither (bimap f g a)
375 SResult -> \f g (AHEither a) -> AHEither (bimap f g a)
376 SInsert -> \f g (AHEither a) -> AHEither (bimap f g a)
377 SName -> \f g (AHEither a) -> AHEither (bimap f g a)
378 SReify context -> \f g (AHEither a) -> AHEither (sbimapEither context f g a)
381sfromColumnsEither :: (Table (Reify context) a, Table (Reify context) b)
382 => SContext context
383 -> HEitherTable (Columns a) (Columns b) (Col (Reify context))
384 -> AHEither context a b
385sfromColumnsEither = \case
386 SAggregate ->
387 AHEither .
388 bimap (fromColumns . hreify) (fromColumns . hreify) .
389 fromColumns .
390 hunreify
391 SExpr ->
392 AHEither .
393 bimap (fromColumns . hreify) (fromColumns . hreify) .
394 fromColumns .
395 hunreify
396 SResult ->
397 AHEither .
398 bimap (fromColumns . hreify) (fromColumns . hreify) .
399 fromColumns .
400 hunreify
401 SInsert ->
402 AHEither .
403 bimap (fromColumns . hreify) (fromColumns . hreify) .
404 fromColumns .
405 hunreify
406 SName ->
407 AHEither .
408 bimap (fromColumns . hreify) (fromColumns . hreify) .
409 fromColumns .
410 hunreify
411 SReify context ->
412 AHEither .
413 sbimapEither context (fromColumns . hreify) (fromColumns . hreify) .
414 sfromColumnsEither context .
415 hunreify
418stoColumnsEither :: (Table (Reify context) a, Table (Reify context) b)
419 => SContext context
420 -> AHEither context a b
421 -> HEitherTable (Columns a) (Columns b) (Col (Reify context))
422stoColumnsEither = \case
423 SAggregate ->
424 hreify .
425 toColumns .
426 bimap (hunreify . toColumns) (hunreify . toColumns) .
427 (\(AHEither a) -> a)
428 SExpr ->
429 hreify .
430 toColumns .
431 bimap (hunreify . toColumns) (hunreify . toColumns) .
432 (\(AHEither a) -> a)
433 SResult ->
434 hreify .
435 toColumns .
436 bimap (hunreify . toColumns) (hunreify . toColumns) .
437 (\(AHEither a) -> a)
438 SInsert ->
439 hreify .
440 toColumns .
441 bimap (hunreify . toColumns) (hunreify . toColumns) .
442 (\(AHEither a) -> a)
443 SName ->
444 hreify .
445 toColumns .
446 bimap (hunreify . toColumns) (hunreify . toColumns) .
447 (\(AHEither a) -> a)
448 SReify context ->
449 hreify .
450 stoColumnsEither context .
451 sbimapEither context (hunreify . toColumns) (hunreify . toColumns) .
452 (\(AHEither a) -> a)
455smapList :: Congruent a b
456 => SContext context
457 -> (a -> b)
458 -> (HListTable (Columns a) (Col (Context a)) -> HListTable (Columns b) (Col (Context b)))
459 -> AHList context a
460 -> AHList context b
461smapList = \case
462 SAggregate -> \_ f (AHList (ListTable a)) -> AHList (ListTable (f a))
463 SExpr -> \_ f (AHList (ListTable a)) -> AHList (ListTable (f a))
464 SResult -> \f _ (AHList as) -> AHList (fmap f as)
465 SInsert -> \_ f (AHList (ListTable a)) -> AHList (ListTable (f a))
466 SName -> \_ f (AHList (ListTable a)) -> AHList (ListTable (f a))
467 SReify context -> \f g (AHList as) -> AHList (smapList context f g as)
470sfromColumnsList :: Table (Reify context) a
471 => SContext context
472 -> HListTable (Columns a) (Col (Reify context))
473 -> AHList context a
474sfromColumnsList = \case
475 SAggregate -> AHList . ListTable
476 SExpr -> AHList . ListTable
477 SResult -> AHList . fmap (fromColumns . hreify) . fromColumns . hunreify
478 SInsert -> AHList . ListTable
479 SName -> AHList . ListTable
480 SReify context ->
481 AHList .
482 smapList context (fromColumns . hreify) hreify .
483 sfromColumnsList context .
484 hunreify
487stoColumnsList :: Table (Reify context) a
488 => SContext context
489 -> AHList context a
490 -> HListTable (Columns a) (Col (Reify context))
491stoColumnsList = \case
492 SAggregate -> \(AHList (ListTable a)) -> a
493 SExpr -> \(AHList (ListTable a)) -> a
494 SResult ->
495 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHList a) -> a)
496 SInsert -> \(AHList (ListTable a)) -> a
497 SName -> \(AHList (ListTable a)) -> a
498 SReify context ->
499 hreify .
500 stoColumnsList context .
501 smapList context (hunreify . toColumns) hunreify .
502 (\(AHList a) -> a)
505smapMaybe :: ()
506 => SContext context
507 -> (a -> b)
508 -> AHMaybe context a
509 -> AHMaybe context b
510smapMaybe = \case
511 SAggregate -> \f (AHMaybe a) -> AHMaybe (fmap f a)
512 SExpr -> \f (AHMaybe a) -> AHMaybe (fmap f a)
513 SResult -> \f (AHMaybe a) -> AHMaybe (fmap f a)
514 SInsert -> \f (AHMaybe a) -> AHMaybe (fmap f a)
515 SName -> \f (AHMaybe a) -> AHMaybe (fmap f a)
516 SReify context -> \f (AHMaybe a) -> AHMaybe (smapMaybe context f a)
519sfromColumnsMaybe :: Table (Reify context) a
520 => SContext context
521 -> HMaybeTable (Columns a) (Col (Reify context))
522 -> AHMaybe context a
523sfromColumnsMaybe = \case
524 SAggregate -> AHMaybe . fmap (fromColumns . hreify) . fromColumns . hunreify
525 SExpr -> AHMaybe . fmap (fromColumns . hreify) . fromColumns . hunreify
526 SResult -> AHMaybe . fmap (fromColumns . hreify) . fromColumns . hunreify
527 SInsert -> AHMaybe . fmap (fromColumns . hreify) . fromColumns . hunreify
528 SName -> AHMaybe . fmap (fromColumns . hreify) . fromColumns . hunreify
529 SReify context ->
530 AHMaybe .
531 smapMaybe context (fromColumns . hreify) .
532 sfromColumnsMaybe context .
533 hunreify
536stoColumnsMaybe :: Table (Reify context) a
537 => SContext context
538 -> AHMaybe context a
539 -> HMaybeTable (Columns a) (Col (Reify context))
540stoColumnsMaybe = \case
541 SAggregate ->
542 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHMaybe a) -> a)
543 SExpr ->
544 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHMaybe a) -> a)
545 SResult ->
546 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHMaybe a) -> a)
547 SInsert ->
548 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHMaybe a) -> a)
549 SName ->
550 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHMaybe a) -> a)
551 SReify context ->
552 hreify .
553 stoColumnsMaybe context .
554 smapMaybe context (hunreify . toColumns) .
555 (\(AHMaybe a) -> a)
558smapNonEmpty :: Congruent a b
559 => SContext context
560 -> (a -> b)
561 -> (HNonEmptyTable (Columns a) (Col (Context a)) -> HNonEmptyTable (Columns b) (Col (Context b)))
562 -> AHNonEmpty context a
563 -> AHNonEmpty context b
564smapNonEmpty = \case
565 SAggregate -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
566 SExpr -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
567 SResult -> \f _ (AHNonEmpty as) -> AHNonEmpty (fmap f as)
568 SInsert -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
569 SName -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
570 SReify context -> \f g (AHNonEmpty as) -> AHNonEmpty (smapNonEmpty context f g as)
573sfromColumnsNonEmpty :: Table (Reify context) a
574 => SContext context
575 -> HNonEmptyTable (Columns a) (Col (Reify context))
576 -> AHNonEmpty context a
577sfromColumnsNonEmpty = \case
578 SAggregate -> AHNonEmpty . NonEmptyTable
579 SExpr -> AHNonEmpty . NonEmptyTable
580 SResult ->
581 AHNonEmpty . fmap (fromColumns . hreify) . fromColumns . hunreify
582 SInsert -> AHNonEmpty . NonEmptyTable
583 SName -> AHNonEmpty . NonEmptyTable
584 SReify context ->
585 AHNonEmpty .
586 smapNonEmpty context (fromColumns . hreify) hreify .
587 sfromColumnsNonEmpty context .
588 hunreify
591stoColumnsNonEmpty :: Table (Reify context) a
592 => SContext context
593 -> AHNonEmpty context a
594 -> HNonEmptyTable (Columns a) (Col (Reify context))
595stoColumnsNonEmpty = \case
596 SAggregate -> \(AHNonEmpty (NonEmptyTable a)) -> a
597 SExpr -> \(AHNonEmpty (NonEmptyTable a)) -> a
598 SResult ->
599 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHNonEmpty a) -> a)
600 SInsert -> \(AHNonEmpty (NonEmptyTable a)) -> a
601 SName -> \(AHNonEmpty (NonEmptyTable a)) -> a
602 SReify context ->
603 hreify .
604 stoColumnsNonEmpty context .
605 smapNonEmpty context (hunreify . toColumns) hunreify .
606 (\(AHNonEmpty a) -> a)
609sbimapThese :: ()
610 => SContext context
611 -> (a -> c)
612 -> (b -> d)
613 -> AHThese context a b
614 -> AHThese context c d
615sbimapThese = \case
616 SAggregate -> \f g (AHThese a) -> AHThese (bimap f g a)
617 SExpr -> \f g (AHThese a) -> AHThese (bimap f g a)
618 SResult -> \f g (AHThese a) -> AHThese (bimap f g a)
619 SInsert -> \f g (AHThese a) -> AHThese (bimap f g a)
620 SName -> \f g (AHThese a) -> AHThese (bimap f g a)
621 SReify context -> \f g (AHThese a) -> AHThese (sbimapThese context f g a)
624sfromColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
625 => SContext context
626 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
627 -> AHThese context a b
628sfromColumnsThese = \case
629 SAggregate ->
630 AHThese .
631 bimap (fromColumns . hreify) (fromColumns . hreify) .
632 fromColumns .
633 hunreify
634 SExpr ->
635 AHThese .
636 bimap (fromColumns . hreify) (fromColumns . hreify) .
637 fromColumns .
638 hunreify
639 SResult ->
640 AHThese .
641 bimap (fromColumns . hreify) (fromColumns . hreify) .
642 fromColumns .
643 hunreify
644 SInsert ->
645 AHThese .
646 bimap (fromColumns . hreify) (fromColumns . hreify) .
647 fromColumns .
648 hunreify
649 SName ->
650 AHThese .
651 bimap (fromColumns . hreify) (fromColumns . hreify) .
652 fromColumns .
653 hunreify
654 SReify context ->
655 AHThese .
656 sbimapThese context (fromColumns . hreify) (fromColumns . hreify) .
657 sfromColumnsThese context .
658 hunreify
661stoColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
662 => SContext context
663 -> AHThese context a b
664 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
665stoColumnsThese = \case
666 SAggregate ->
667 hreify .
668 toColumns .
669 bimap (hunreify . toColumns) (hunreify . toColumns) .
670 (\(AHThese a) -> a)
671 SExpr ->
672 hreify .
673 toColumns .
674 bimap (hunreify . toColumns) (hunreify . toColumns) .
675 (\(AHThese a) -> a)
676 SResult ->
677 hreify .
678 toColumns .
679 bimap (hunreify . toColumns) (hunreify . toColumns) .
680 (\(AHThese a) -> a)
681 SInsert ->
682 hreify .
683 toColumns .
684 bimap (hunreify . toColumns) (hunreify . toColumns) .
685 (\(AHThese a) -> a)
686 SName ->
687 hreify .
688 toColumns .
689 bimap (hunreify . toColumns) (hunreify . toColumns) .
690 (\(AHThese a) -> a)
691 SReify context ->
692 hreify .
693 stoColumnsThese context .
694 sbimapThese context (hunreify . toColumns) (hunreify . toColumns) .
695 (\(AHThese a) -> a)