1{-# language DataKinds #-}
2{-# language DerivingStrategies #-}
3{-# language FlexibleContexts #-}
4{-# language FlexibleInstances #-}
6{-# language GeneralizedNewtypeDeriving #-}
7{-# language MultiParamTypeClasses #-}
8{-# language RankNTypes #-}
9{-# language StandaloneKindSignatures #-}
10{-# language TypeFamilies #-}
11{-# language UndecidableInstances #-}
13module Rel8.Schema.Name
21import Data.Functor.Identity ( Identity( Identity ) )
22import Data.Kind ( Constraint, Type )
23import Data.String ( IsString )
27import qualified Opaleye.Internal.HaskellDB.Sql as Opaleye
28import qualified Opaleye.Internal.HaskellDB.Sql.Print as Opaleye
31import Text.PrettyPrint ( Doc )
34import Rel8.Expr ( Expr )
35import qualified Rel8.Schema.Kind as K
36import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
37import Rel8.Schema.Null ( Sql )
39 ( Table, Columns, Context, fromColumns, toColumns
40 , FromExprs, fromResult, toResult
43import Rel8.Table.Transpose ( Transposes )
44import Rel8.Type ( DBType )
47-- | A @Name@ is the name of a column, as it would be defined in a table's
48-- schema definition. You can construct names by using the @OverloadedStrings@
49-- extension and writing string literals. This is typically done when providing
50-- a 'TableSchema' value.
52newtype Name a = Name String
54 deriving newtype IsString
57instance Sql DBType a => Table Name (Name a) where
58 type Columns (Name a) = HIdentity a
59 type Context (Name a) = Name
60 type FromExprs (Name a) = a
61 type Transpose to (Name a) = to a
63 toColumns a = HIdentity a
64 fromColumns (HIdentity a) = a
65 toResult a = HIdentity (Identity a)
66 fromResult (HIdentity (Identity a)) = a
69-- | @Selects a b@ means that @a@ is a schema (i.e., a 'Table' of 'Name's) for
70-- the 'Expr' columns in @b@.
71type Selects :: Type -> Type -> Constraint
72class Transposes Name Expr names exprs => Selects names exprs
73instance Transposes Name Expr names exprs => Selects names exprs
76ppColumn :: String -> Doc
77ppColumn = Opaleye.ppSqlExpr . Opaleye.ColumnSqlExpr . Opaleye.SqlColumn
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list