on dev help sign in
some cleanup and renaming
cebc2a7Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−7
@@ -88,8 +88,8 @@ statements
88-- database, like a `createTable`, `dropTable`, or `alterTable` command.
88-- database, like a `createTable`, `dropTable`, or `alterTable` command.
89-- `Definition`s may be composed using the `>>>` operator.
89-- `Definition`s may be composed using the `>>>` operator.
90newtype Definition
90newtype Definition
91− (schema0 :: SchemaType)
91+ (schema0 :: TablesType)
92− (schema1 :: SchemaType)
92+ (schema1 :: TablesType)
93 = UnsafeDefinition { renderDefinition :: ByteString }
93 = UnsafeDefinition { renderDefinition :: ByteString }
94 deriving (GHC.Generic,Show,Eq,Ord,NFData)
94 deriving (GHC.Generic,Show,Eq,Ord,NFData)
95
95
@@ -153,7 +153,7 @@ createTable table columns constraints = UnsafeDefinition $
153-- violate a constraint, an error is raised. This applies
153-- violate a constraint, an error is raised. This applies
154-- even if the value came from the default value definition.
154-- even if the value came from the default value definition.
155newtype TableConstraintExpression
155newtype TableConstraintExpression
156− (schema :: SchemaType)
156+ (schema :: TablesType)
157 (columns :: ColumnsType)
157 (columns :: ColumnsType)
158 (tableConstraint :: TableConstraint)
158 (tableConstraint :: TableConstraint)
159 = UnsafeTableConstraintExpression
159 = UnsafeTableConstraintExpression
@@ -185,7 +185,7 @@ renderColumn (Column column) = renderAlias column
185-- :}
185-- :}
186-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CONSTRAINT inequality CHECK ((a > b)));"
186-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CONSTRAINT inequality CHECK ((a > b)));"
187check
187check
188− :: Condition '[table ::: UnconstrainColumns columns] 'Ungrouped '[]
188+ :: Condition '[table ::: ColumnsToRelation columns] 'Ungrouped '[]
189 -- ^ condition to check
189 -- ^ condition to check
190 -> TableConstraintExpression schema columns 'Check
190 -> TableConstraintExpression schema columns 'Check
191check condition = UnsafeTableConstraintExpression $
191check condition = UnsafeTableConstraintExpression $
@@ -273,7 +273,7 @@ primaryKey columns = UnsafeTableConstraintExpression $
273-- "CREATE TABLE users (id serial, username text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id)); CREATE TABLE emails (id serial, userid integer NOT NULL, email text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (userid) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT);"
273-- "CREATE TABLE users (id serial, username text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id)); CREATE TABLE emails (id serial, userid integer NOT NULL, email text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (userid) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT);"
274foreignKey
274foreignKey
275 :: ( Has table schema reftable
275 :: ( Has table schema reftable
276− , refcolumns ~ UnconstrainTable reftable
276+ , refcolumns ~ TableToColumns reftable
277 , SameTypes subcolumns refsubcolumns
277 , SameTypes subcolumns refsubcolumns
278 , AllNotNull subcolumns
278 , AllNotNull subcolumns
279 , SOP.SListI subcolumns
279 , SOP.SListI subcolumns
@@ -394,7 +394,7 @@ alterTableRename table0 table1 = UnsafeDefinition $
394addConstraint
394addConstraint
395 :: KnownSymbol constraintName
395 :: KnownSymbol constraintName
396 => Alias constraintName
396 => Alias constraintName
397− -> TableConstraintExpression schema (UnconstrainTable table) constraint
397+ -> TableConstraintExpression schema (TableToColumns table) constraint
398 -> AlterTable schema table (AddConstraint constraintName constraint table)
398 -> AlterTable schema table (AddConstraint constraintName constraint table)
399addConstraint constraintName constraint = UnsafeAlterTable $
399addConstraint constraintName constraint = UnsafeAlterTable $
400 "ADD" <+> "CONSTRAINT" <+> renderAlias constraintName
400 "ADD" <+> "CONSTRAINT" <+> renderAlias constraintName
@@ -412,7 +412,7 @@ dropConstraint constraint = UnsafeAlterTable $
412-- | An `AlterTable` describes the alteration to perform on the columns
412-- | An `AlterTable` describes the alteration to perform on the columns
413-- of a table.
413-- of a table.
414newtype AlterTable
414newtype AlterTable
415− (schema :: SchemaType)
415+ (schema :: TablesType)
416 (table0 :: TableType)
416 (table0 :: TableType)
417 (table1 :: TableType) =
417 (table1 :: TableType) =
418 UnsafeAlterTable {renderAlterTable :: ByteString}
418 UnsafeAlterTable {renderAlterTable :: ByteString}
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+3−3
@@ -173,7 +173,7 @@ values from primitive expression using arithmetic, logical,
173and other operations.
173and other operations.
174-}
174-}
175newtype Expression
175newtype Expression
176− (relation :: RelationProduct)
176+ (relation :: RelationsType)
177 (grouping :: Grouping)
177 (grouping :: Grouping)
178 (params :: [NullityType])
178 (params :: [NullityType])
179 (ty :: NullityType)
179 (ty :: NullityType)
@@ -939,13 +939,13 @@ tables
939-- | A `Subtable` from a table expression is a way
939-- | A `Subtable` from a table expression is a way
940-- to call a table reference by its alias.
940-- to call a table reference by its alias.
941newtype Subtable
941newtype Subtable
942− (table :: RelationProduct)
942+ (table :: RelationsType)
943 (columns :: RelationType)
943 (columns :: RelationType)
944 = UnsafeSubtable { renderSubtable :: ByteString }
944 = UnsafeSubtable { renderSubtable :: ByteString }
945 deriving (GHC.Generic,Show,Eq,Ord,NFData)
945 deriving (GHC.Generic,Show,Eq,Ord,NFData)
946instance Has
946instance Has
947 (subtable :: Symbol)
947 (subtable :: Symbol)
948− (table :: RelationProduct)
948+ (table :: RelationsType)
949 (columns :: RelationType)
949 (columns :: RelationType)
950 => IsLabel subtable (Subtable table columns) where
950 => IsLabel subtable (Subtable table columns) where
951 fromLabel = UnsafeSubtable $ renderAlias (Alias @subtable)
951 fromLabel = UnsafeSubtable $ renderAlias (Alias @subtable)
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+13−13
@@ -58,7 +58,7 @@ import Squeal.PostgreSQL.Schema
58-- `deleteFrom`. A `Query` is also considered a `Manipulation` even though
58-- `deleteFrom`. A `Query` is also considered a `Manipulation` even though
59-- it does not modify data.
59-- it does not modify data.
60newtype Manipulation
60newtype Manipulation
61− (schema :: SchemaType)
61+ (schema :: TablesType)
62 (params :: [NullityType])
62 (params :: [NullityType])
63 (columns :: RelationType)
63 (columns :: RelationType)
64 = UnsafeManipulation { renderManipulation :: ByteString }
64 = UnsafeManipulation { renderManipulation :: ByteString }
@@ -179,7 +179,7 @@ insertRows
179 :: ( SOP.SListI columns
179 :: ( SOP.SListI columns
180 , SOP.SListI results
180 , SOP.SListI results
181 , Has tab schema table
181 , Has tab schema table
182− , columns ~ UnconstrainTable table )
182+ , columns ~ TableToColumns table )
183 => Alias tab -- ^ table to insert into
183 => Alias tab -- ^ table to insert into
184 -> NP (Aliased (ColumnValue '[] params)) columns
184 -> NP (Aliased (ColumnValue '[] params)) columns
185 -> [NP (Aliased (ColumnValue '[] params)) columns]
185 -> [NP (Aliased (ColumnValue '[] params)) columns]
@@ -208,9 +208,9 @@ insertQuery
208 :: ( SOP.SListI columns
208 :: ( SOP.SListI columns
209 , SOP.SListI results
209 , SOP.SListI results
210 , Has tab schema table
210 , Has tab schema table
211− , columns ~ UnconstrainTable table )
211+ , columns ~ TableToColumns table )
212 => Alias tab -- ^ table to insert into
212 => Alias tab -- ^ table to insert into
213− -> Query schema params (UnconstrainColumns columns)
213+ -> Query schema params (ColumnsToRelation columns)
214 -> ConflictClause columns params
214 -> ConflictClause columns params
215 -- ^ what to do in case of constraint conflict
215 -- ^ what to do in case of constraint conflict
216 -> ReturningClause columns params results -- ^ results to return
216 -> ReturningClause columns params results -- ^ results to return
@@ -248,10 +248,10 @@ data ReturningClause
248 (results :: RelationType)
248 (results :: RelationType)
249 where
249 where
250 ReturningStar
250 ReturningStar
251− :: ReturningClause columns params (UnconstrainColumns columns)
251+ :: ReturningClause columns params (ColumnsToRelation columns)
252 Returning
252 Returning
253 :: NP
253 :: NP
254− (Aliased (Expression '[table ::: (UnconstrainColumns columns)] 'Ungrouped params))
254+ (Aliased (Expression '[table ::: (ColumnsToRelation columns)] 'Ungrouped params))
255 results
255 results
256 -> ReturningClause columns params results
256 -> ReturningClause columns params results
257
257
@@ -275,8 +275,8 @@ data ConflictClause (columns :: ColumnsType) params where
275 OnConflictDoRaise :: ConflictClause columns params
275 OnConflictDoRaise :: ConflictClause columns params
276 OnConflictDoNothing :: ConflictClause columns params
276 OnConflictDoNothing :: ConflictClause columns params
277 OnConflictDoUpdate
277 OnConflictDoUpdate
278− :: NP (Aliased (ColumnValue (UnconstrainColumns columns) params)) columns
278+ :: NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
279− -> [Condition '[table ::: UnconstrainColumns columns] 'Ungrouped params]
279+ -> [Condition '[table ::: ColumnsToRelation columns] 'Ungrouped params]
280 -> ConflictClause columns params
280 -> ConflictClause columns params
281
281
282-- | Render a `ConflictClause`.
282-- | Render a `ConflictClause`.
@@ -327,11 +327,11 @@ update
327 :: ( SOP.SListI columns
327 :: ( SOP.SListI columns
328 , SOP.SListI results
328 , SOP.SListI results
329 , Has tab schema table
329 , Has tab schema table
330− , columns ~ UnconstrainTable table )
330+ , columns ~ TableToColumns table )
331 => Alias tab -- ^ table to update
331 => Alias tab -- ^ table to update
332− -> NP (Aliased (ColumnValue (UnconstrainColumns columns) params)) columns
332+ -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
333 -- ^ modified values to replace old values
333 -- ^ modified values to replace old values
334− -> Condition '[tab ::: UnconstrainColumns columns] 'Ungrouped params
334+ -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
335 -- ^ condition under which to perform update on a row
335 -- ^ condition under which to perform update on a row
336 -> ReturningClause columns params results -- ^ results to return
336 -> ReturningClause columns params results -- ^ results to return
337 -> Manipulation schema params results
337 -> Manipulation schema params results
@@ -374,9 +374,9 @@ DELETE statements
374deleteFrom
374deleteFrom
375 :: ( SOP.SListI results
375 :: ( SOP.SListI results
376 , Has tab schema table
376 , Has tab schema table
377− , columns ~ UnconstrainTable table )
377+ , columns ~ TableToColumns table )
378 => Alias tab -- ^ table to delete from
378 => Alias tab -- ^ table to delete from
379− -> Condition '[tab ::: UnconstrainColumns columns] 'Ungrouped params
379+ -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
380 -- ^ condition under which to delete a row
380 -- ^ condition under which to delete a row
381 -> ReturningClause columns params results -- ^ results to return
381 -> ReturningClause columns params results -- ^ results to return
382 -> Manipulation schema params results
382 -> Manipulation schema params results
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+4−4
@@ -100,8 +100,8 @@ import qualified Control.Monad.Trans.RWS.Lazy as Lazy
100import qualified Control.Monad.Trans.RWS.Strict as Strict
100import qualified Control.Monad.Trans.RWS.Strict as Strict
101
101
102-- | A `Connection` consists of a `Database.PostgreSQL.LibPQ`
102-- | A `Connection` consists of a `Database.PostgreSQL.LibPQ`
103−-- `Database.PastgreSQL.LibPQ.Connection` and a phantom `SchemaType`
103+-- `Database.PastgreSQL.LibPQ.Connection` and a phantom `TablesType`
104−newtype Connection (schema :: SchemaType) =
104+newtype Connection (schema :: TablesType) =
105 Connection { unConnection :: LibPQ.Connection }
105 Connection { unConnection :: LibPQ.Connection }
106
106
107{- | Makes a new connection to the database server.
107{- | Makes a new connection to the database server.
@@ -153,8 +153,8 @@ withConnection connString action = do
153-- | We keep track of the schema via an Atkey indexed state monad transformer,
153-- | We keep track of the schema via an Atkey indexed state monad transformer,
154-- `PQ`.
154-- `PQ`.
155newtype PQ
155newtype PQ
156− (schema0 :: SchemaType)
156+ (schema0 :: TablesType)
157− (schema1 :: SchemaType)
157+ (schema1 :: TablesType)
158 (m :: Type -> Type)
158 (m :: Type -> Type)
159 (x :: Type) =
159 (x :: Type) =
160 PQ { runPQ :: Connection schema0 -> m (x, Connection schema1) }
160 PQ { runPQ :: Connection schema0 -> m (x, Connection schema1) }
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+5−5
@@ -257,7 +257,7 @@ in renderQuery query
257-}
257-}
258
258
259newtype Query
259newtype Query
260− (schema :: SchemaType)
260+ (schema :: TablesType)
261 (params :: [NullityType])
261 (params :: [NullityType])
262 (columns :: RelationType)
262 (columns :: RelationType)
263 = UnsafeQuery { renderQuery :: ByteString }
263 = UnsafeQuery { renderQuery :: ByteString }
@@ -419,9 +419,9 @@ Table Expressions
419-- to a table on disk, a so-called base table, but more complex expressions
419-- to a table on disk, a so-called base table, but more complex expressions
420-- can be used to modify or combine base tables in various ways.
420-- can be used to modify or combine base tables in various ways.
421data TableExpression
421data TableExpression
422− (schema :: SchemaType)
422+ (schema :: TablesType)
423 (params :: [NullityType])
423 (params :: [NullityType])
424− (tables :: RelationProduct)
424+ (tables :: RelationsType)
425 (grouping :: Grouping)
425 (grouping :: Grouping)
426 = TableExpression
426 = TableExpression
427 { fromClause :: FromClause schema params tables
427 { fromClause :: FromClause schema params tables
@@ -612,7 +612,7 @@ their placement in SQL.
612-}
612-}
613data FromClause schema params tables where
613data FromClause schema params tables where
614 Table
614 Table
615− :: Aliased (Subtable (UnconstrainSchema schema)) table
615+ :: Aliased (Subtable (TablesToRelations schema)) table
616 -> FromClause schema params '[table]
616 -> FromClause schema params '[table]
617 Subquery
617 Subquery
618 :: Aliased (Query schema params) table
618 :: Aliased (Query schema params) table
@@ -669,7 +669,7 @@ Grouping
669-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
669-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
670-- qualified column @tab.col@.
670-- qualified column @tab.col@.
671data By
671data By
672− (tables :: RelationProduct)
672+ (tables :: RelationsType)
673 (by :: (Symbol,Symbol)) where
673 (by :: (Symbol,Symbol)) where
674 By
674 By
675 :: (HasUnique table tables columns, Has column columns ty)
675 :: (HasUnique table tables columns, Has column columns ty)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+63−55
@@ -39,9 +39,9 @@ module Squeal.PostgreSQL.Schema
39 , ColumnType
39 , ColumnType
40 , ColumnsType
40 , ColumnsType
41 , RelationType
41 , RelationType
42− , RelationProduct
42+ , RelationsType
43 , TableType
43 , TableType
44− , SchemaType
44+ , TablesType
45 , Grouping (..)
45 , Grouping (..)
46 -- * Constraints
46 -- * Constraints
47 , PGNum
47 , PGNum
@@ -77,11 +77,9 @@ module Squeal.PostgreSQL.Schema
77 , SameFields
77 , SameFields
78 -- * PostgreSQL Constraints
78 -- * PostgreSQL Constraints
79 , (:=>)
79 , (:=>)
80− , Unconstraint
80+ , ColumnsToRelation
81− , UnconstrainColumn
81+ , TableToColumns
82− , UnconstrainColumns
82+ , TablesToRelations
83− , UnconstrainTable
84− , UnconstrainSchema
85 , ColumnConstraint (..)
83 , ColumnConstraint (..)
86 , TableConstraint (..)
84 , TableConstraint (..)
87 , Aliases
85 , Aliases
@@ -131,44 +129,74 @@ data NullityType
131 = Null PGType -- ^ @NULL@ may be present
129 = Null PGType -- ^ @NULL@ may be present
132 | NotNull PGType -- ^ @NULL@ is absent
130 | NotNull PGType -- ^ @NULL@ is absent
133
131
134−type RelationType = [(Symbol,NullityType)]
132+-- | `:=>` is a type level pair between an "constraint" and some type,
135−type RelationProduct = [(Symbol,RelationType)]
133+-- either a `ColumnConstraint` and a `NullityType` or a row of
134+-- `TableConstraint`s and a `TableType`.
135+type (:=>) constraint ty = '(constraint,ty)
136+infixr 7 :=>
137+
138+-- | `:::` is like a promoted version of `As`, a type level pair between
139+-- an alias and some type, like a column alias and either a `ColumnType` or
140+-- `NullityType` or a table alias and either a `TableType` or a `RelationType`
141+-- or a constraint alias and a `TableConstraint`.
142+type (:::) (alias :: Symbol) ty = '(alias,ty)
143+infixr 6 :::
144+
145+-- | `ColumnConstraint` encodes the allowance of @DEFAULT@.
146+data ColumnConstraint
147+ = Def -- ^ @DEFAULT@ is available for inserts and updates
148+ | NoDef -- ^ @DEFAULT@ is unavailable for inserts and updates
136
149
137−-- | `ColumnType` encodes the allowance of @DEFAULT@ and the only way
150+-- | `ColumnType` encodes the allowance of @DEFAULT@ and @NULL@ and the
138−-- to generate an `Optional` `Squeal.PostgreSQL.Expression.Expression`
151+-- base `PGType` for a column.
139−-- is to use `Squeal.PostgreSQL.Expression.def`,
140−-- `Squeal.PostgreSQL.Expression.unDef` or
141−-- `Squeal.PostgreSQL.Expression.param`.
142type ColumnType = (ColumnConstraint,NullityType)
152type ColumnType = (ColumnConstraint,NullityType)
143
153
144−-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
154+-- | `ColumnsType` is a row of `ColumnType`s.
145type ColumnsType = [(Symbol,ColumnType)]
155type ColumnsType = [(Symbol,ColumnType)]
146
156
147−type TableType = (TableConstraints,ColumnsType)
157+-- | `TableConstraint` encodes various forms of data constraints
148−type SchemaType = [(Symbol,TableType)]
158+-- of columns in a table.
159+data TableConstraint
160+ = Check
161+ | Unique [Symbol]
162+ | PrimaryKey [Symbol]
163+ | ForeignKey [Symbol] Symbol [Symbol]
149
164
150−type family UnconstrainColumn (ty :: ColumnType) :: NullityType where
165+-- | `TableType` encodes a row of constraints on a table as well as the types
151− UnconstrainColumn (constraint :=> ty) = ty
166+-- of its columns.
167+type TableType = ([(Symbol,TableConstraint)],ColumnsType)
168+
169+-- | `TablesType` is a row of `TableType`s, thought of as a union.
170+type TablesType = [(Symbol,TableType)]
171+
172+-- | `RelationType` is a row of `NullityType`
173+type RelationType = [(Symbol,NullityType)]
152
174
153−type family UnconstrainColumns (columns :: ColumnsType) :: RelationType where
175+-- | `RelationsType` is a row of `RelationType`s, thought of as a product.
154− UnconstrainColumns '[] = '[]
176+type RelationsType = [(Symbol,RelationType)]
155− UnconstrainColumns (column ::: ty ': columns) =
156− column ::: UnconstrainColumn ty ': UnconstrainColumns columns
157
177
178+-- | `ColumnsToRelation` removes column constraints.
158−type family UnconstrainTable (table :: TableType) :: ColumnsType where
179+type family ColumnsToRelation (columns :: ColumnsType) :: RelationType where
159− UnconstrainTable (constraints :=> columns) = columns
180+ ColumnsToRelation '[] = '[]
181+ ColumnsToRelation (column ::: constraint :=> ty ': columns) =
182+ column ::: ty ': ColumnsToRelation columns
160
183
161−type family UnconstrainSchema (schema :: SchemaType) :: RelationProduct where
184+-- | `TableToColumns` removes table constraints.
162− UnconstrainSchema '[] = '[]
185+type family TableToColumns (table :: TableType) :: ColumnsType where
163− UnconstrainSchema (tab ::: constraints :=> columns ': tables) =
186+ TableToColumns (constraints :=> columns) = columns
164− tab ::: UnconstrainColumns columns ': UnconstrainSchema tables
187+
188+-- | `TablesToRelations` removes both table and column constraints.
189+type family TablesToRelations (tables :: TablesType) :: RelationsType where
190+ TablesToRelations '[] = '[]
191+ TablesToRelations (alias ::: constraint :=> columns ': tables) =
192+ alias ::: ColumnsToRelation columns ': TablesToRelations tables
165
193
166-- | `Grouping` is an auxiliary namespace, created by
194-- | `Grouping` is an auxiliary namespace, created by
167-- @GROUP BY@ clauses (`Squeal.PostgreSQL.Query.group`), and used
195-- @GROUP BY@ clauses (`Squeal.PostgreSQL.Query.group`), and used
168-- for typesafe aggregation
196-- for typesafe aggregation
169data Grouping
197data Grouping
170− = Ungrouped
198+ = Ungrouped -- ^ no aggregation permitted
171− | Grouped [(Symbol,Symbol)]
199+ | Grouped [(Symbol,Symbol)] -- ^ aggregation required for any column which is not grouped
172
200
173-- | `PGNum` is a constraint on `PGType` whose
201-- | `PGNum` is a constraint on `PGType` whose
174-- `Squeal.PostgreSQL.Expression.Expression`s have a `Num` constraint.
202-- `Squeal.PostgreSQL.Expression.Expression`s have a `Num` constraint.
@@ -186,12 +214,6 @@ type PGFloating ty = In ty '[ 'PGfloat4, 'PGfloat8, 'PGnumeric]
186-- `Squeal.PostgreSQL.Expression.mod_` functions.
214-- `Squeal.PostgreSQL.Expression.mod_` functions.
187type PGIntegral ty = In ty '[ 'PGint2, 'PGint4, 'PGint8]
215type PGIntegral ty = In ty '[ 'PGint2, 'PGint4, 'PGint8]
188
216
189−-- | `:::` is like a promoted version of `As`, a type level pair between
190−-- an alias and some type, usually a column alias and a `ColumnType` or
191−-- a table alias and a `ColumnsType`.
192−type (:::) (alias :: Symbol) (ty :: polykind) = '(alias,ty)
193−infixr 6 :::
194−
195-- | `Alias`es are proxies for a type level string or `Symbol`
217-- | `Alias`es are proxies for a type level string or `Symbol`
196-- and have an `IsLabel` instance so that with @-XOverloadedLabels@
218-- and have an `IsLabel` instance so that with @-XOverloadedLabels@
197--
219--
@@ -227,7 +249,7 @@ deriving instance Ord (expression ty)
227 => Ord (Aliased expression (alias ::: ty))
249 => Ord (Aliased expression (alias ::: ty))
228instance KnownSymbol alias
250instance KnownSymbol alias
229 => IsLabel alias (expression ty -> Aliased expression (alias ::: ty))
251 => IsLabel alias (expression ty -> Aliased expression (alias ::: ty))
230− where fromLabel = \ expression -> expression `As` Alias @alias
252+ where fromLabel expression = expression `As` Alias @alias
231
253
232-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
254-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
233-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
255-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
@@ -290,10 +312,10 @@ type family NullifyColumns (columns :: RelationType) :: RelationType where
290 NullifyColumns (column ::: ty ': columns) =
312 NullifyColumns (column ::: ty ': columns) =
291 column ::: NullifyType ty ': NullifyColumns columns
313 column ::: NullifyType ty ': NullifyColumns columns
292
314
293−-- | `NullifyTables` is an idempotent that nullifies a `RelationProduct`
315+-- | `NullifyTables` is an idempotent that nullifies a `RelationsType`
294-- used to nullify the left or right hand side of an outer join
316-- used to nullify the left or right hand side of an outer join
295-- in a `Squeal.PostgreSQL.Query.FromClause`.
317-- in a `Squeal.PostgreSQL.Query.FromClause`.
296−type family NullifyTables (tables :: RelationProduct) :: RelationProduct where
318+type family NullifyTables (tables :: RelationsType) :: RelationsType where
297 NullifyTables '[] = '[]
319 NullifyTables '[] = '[]
298 NullifyTables (table ::: columns ': tables) =
320 NullifyTables (table ::: columns ': tables) =
299 table ::: NullifyColumns columns ': NullifyTables tables
321 table ::: NullifyColumns columns ': NullifyTables tables
@@ -373,21 +395,7 @@ type family SameFields
373 columns
395 columns
374 = AllZip SameField fields columns
396 = AllZip SameField fields columns
375
397
376−type (:=>) (constraints :: constraint) ty = '(constraints,ty)
377−infixr 7 :=>
378−
379−data ColumnConstraint
380− = Def
381− | NoDef
382−
383−data TableConstraint
384− = Check
385− | Unique [Symbol]
386− | PrimaryKey [Symbol]
387− | ForeignKey [Symbol] Symbol [Symbol]
388−
389−type TableConstraints = [(Symbol,TableConstraint)]
390−type Unconstraint = ('[] :: TableConstraints)
398+-- type Unconstraint = ('[] :: [(Symbol,TableConstraint)])
391
399
392type family Aliases xs where
400type family Aliases xs where
393 Aliases '[] = '[]
401 Aliases '[] = '[]