1{-# language DataKinds #-}
2{-# language DerivingStrategies #-}
3{-# language FlexibleContexts #-}
4{-# language FlexibleInstances #-}
5{-# language GeneralizedNewtypeDeriving #-}
6{-# language MultiParamTypeClasses #-}
7{-# language RankNTypes #-}
8{-# language ScopedTypeVariables #-}
9{-# language StandaloneKindSignatures #-}
10{-# language TypeApplications #-}
11{-# language TypeFamilies #-}
12{-# language UndecidableInstances #-}
13{-# language UndecidableSuperClasses #-}
15module Rel8.Schema.Name
23import Data.Functor.Identity ( Identity )
24import Data.Kind ( Constraint, Type )
25import Data.String ( IsString )
29import Rel8.Expr ( Expr )
30import Rel8.Opaque ( Opaque )
31import Rel8.Schema.Context ( Interpretation, Col )
32import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
33import Rel8.Schema.HTable.Type ( HType( HType ) )
34import qualified Rel8.Schema.Kind as K
35import Rel8.Schema.Nullability ( Sql )
36import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
37import Rel8.Table.Recontextualize ( Recontextualize )
38import Rel8.Type ( DBType )
41-- | A @Name@ is the name of a column, as it would be defined in a table's
42-- schema definition. You can construct names by using the @OverloadedStrings@
43-- extension and writing string literals. This is typically done when providing
44-- a 'TableSchema' value.
46newtype Name a = Name String
48 deriving newtype (IsString, Monoid, Semigroup)
51instance Sql DBType a => Table Name (Name a) where
52 type Columns (Name a) = HType a
53 type Context (Name a) = Name
55 toColumns (Name a) = HType (NameCol a)
56 fromColumns (HType (NameCol a)) = Name a
59instance Sql DBType a => Recontextualize Expr Name (Expr a) (Name a)
62instance Sql DBType a => Recontextualize Identity Name (Identity a) (Name a)
65instance Sql DBType a => Recontextualize Name Expr (Name a) (Expr a)
68instance Sql DBType a => Recontextualize Name Identity (Name a) (Identity a)
71instance Sql DBType a => Recontextualize Name Name (Name a) (Name a)
74instance Interpretation Name where
75 newtype Col Name _spec = NameCol String
78instance Labelable Name where
79 labeler (NameCol a) = NameCol a
80 unlabeler (NameCol a) = NameCol a
83-- | @Selects a b@ means that @a@ is a schema (i.e., a 'Table' of 'Name's) for
84-- the 'Expr' columns in @b@.
85type Selects :: Type -> Type -> Constraint
86class Recontextualize Name Expr names exprs => Selects names exprs
87instance Recontextualize Name Expr names exprs => Selects names exprs
88instance {-# OVERLAPPING #-} Selects (Opaque Name Opaque) (Opaque Expr Opaque)
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