on dev help sign in
simplify a bit
875f8f8Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−12
@@ -142,7 +142,7 @@ createTable tab columns constraints = UnsafeDefinition $
142-- :}
142-- :}
143-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
143-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
144createTableIfNotExists
144createTableIfNotExists
145− :: ( Has table (TablesOf schema) (constraints :=> columns)
145+ :: ( Has table schema ('Table (constraints :=> columns))
146 , SOP.SListI columns
146 , SOP.SListI columns
147 , SOP.SListI constraints )
147 , SOP.SListI constraints )
148 => Alias table -- ^ the name of the table to add
148 => Alias table -- ^ the name of the table to add
@@ -228,7 +228,7 @@ newtype TableConstraintExpression
228-- >>> renderDefinition definition
228-- >>> renderDefinition definition
229-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
229-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
230check
230check
231− :: ( Has alias (TablesOf schema) table
231+ :: ( Has alias schema ('Table table)
232 , HasAll aliases (TableToColumns table) subcolumns )
232 , HasAll aliases (TableToColumns table) subcolumns )
233 => NP Alias aliases
233 => NP Alias aliases
234 -> (forall tab. Condition '[tab ::: ColumnsToRelation subcolumns] 'Ungrouped '[])
234 -> (forall tab. Condition '[tab ::: ColumnsToRelation subcolumns] 'Ungrouped '[])
@@ -259,7 +259,7 @@ check _cols condition = UnsafeTableConstraintExpression $
259-- >>> renderDefinition definition
259-- >>> renderDefinition definition
260-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
260-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
261unique
261unique
262− :: ( Has alias (TablesOf schema) table
262+ :: ( Has alias schema ('Table table)
263 , HasAll aliases (TableToColumns table) subcolumns )
263 , HasAll aliases (TableToColumns table) subcolumns )
264 => NP Alias aliases
264 => NP Alias aliases
265 -> TableConstraintExpression schema alias ('Unique aliases)
265 -> TableConstraintExpression schema alias ('Unique aliases)
@@ -290,7 +290,7 @@ unique columns = UnsafeTableConstraintExpression $
290-- >>> renderDefinition definition
290-- >>> renderDefinition definition
291-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
291-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
292primaryKey
292primaryKey
293− :: ( Has alias (TablesOf schema) table
293+ :: ( Has alias schema ('Table table)
294 , HasAll aliases (TableToColumns table) subcolumns
294 , HasAll aliases (TableToColumns table) subcolumns
295 , AllNotNull subcolumns )
295 , AllNotNull subcolumns )
296 => NP Alias aliases
296 => NP Alias aliases
@@ -401,8 +401,8 @@ type ForeignKeyed schema
401 columns refcolumns
401 columns refcolumns
402 constraints cols
402 constraints cols
403 reftys tys =
403 reftys tys =
404− ( Has child (TablesOf schema) table
404+ ( Has child schema ('Table table)
405− , Has parent (TablesOf schema) reftable
405+ , Has parent schema ('Table reftable)
406 , HasAll columns (TableToColumns table) tys
406 , HasAll columns (TableToColumns table) tys
407 , reftable ~ (constraints :=> cols)
407 , reftable ~ (constraints :=> cols)
408 , HasAll refcolumns cols reftys
408 , HasAll refcolumns cols reftys
@@ -519,7 +519,7 @@ newtype AlterTable
519-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
519-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
520addConstraint
520addConstraint
521 :: ( KnownSymbol alias
521 :: ( KnownSymbol alias
522− , Has tab (TablesOf schema) table0
522+ , Has tab schema ('Table table0)
523 , table0 ~ (constraints :=> columns)
523 , table0 ~ (constraints :=> columns)
524 , table1 ~ (Create alias constraint constraints :=> columns) )
524 , table1 ~ (Create alias constraint constraints :=> columns) )
525 => Alias alias
525 => Alias alias
@@ -543,7 +543,7 @@ addConstraint alias constraint = UnsafeAlterTable $
543-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
543-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
544dropConstraint
544dropConstraint
545 :: ( KnownSymbol constraint
545 :: ( KnownSymbol constraint
546− , Has tab (TablesOf schema) table0
546+ , Has tab schema ('Table table0)
547 , table0 ~ (constraints :=> columns)
547 , table0 ~ (constraints :=> columns)
548 , table1 ~ (Drop constraint constraints :=> columns) )
548 , table1 ~ (Drop constraint constraints :=> columns) )
549 => Alias constraint
549 => Alias constraint
@@ -582,7 +582,7 @@ class AddColumn ty where
582 -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
582 -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
583 addColumn
583 addColumn
584 :: ( KnownSymbol column
584 :: ( KnownSymbol column
585− , Has tab (TablesOf schema) table0
585+ , Has tab schema ('Table table0)
586 , table0 ~ (constraints :=> columns)
586 , table0 ~ (constraints :=> columns)
587 , table1 ~ (constraints :=> Create column ty columns) )
587 , table1 ~ (constraints :=> Create column ty columns) )
588 => Alias column -- ^ column to add
588 => Alias column -- ^ column to add
@@ -611,7 +611,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
611-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
611-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
612dropColumn
612dropColumn
613 :: ( KnownSymbol column
613 :: ( KnownSymbol column
614− , Has tab (TablesOf schema) table0
614+ , Has tab schema ('Table table0)
615 , table0 ~ (constraints :=> columns)
615 , table0 ~ (constraints :=> columns)
616 , table1 ~ (constraints :=> Drop column columns) )
616 , table1 ~ (constraints :=> Drop column columns) )
617 => Alias column -- ^ column to remove
617 => Alias column -- ^ column to remove
@@ -633,7 +633,7 @@ dropColumn column = UnsafeAlterTable $
633renameColumn
633renameColumn
634 :: ( KnownSymbol column0
634 :: ( KnownSymbol column0
635 , KnownSymbol column1
635 , KnownSymbol column1
636− , Has tab (TablesOf schema) table0
636+ , Has tab schema ('Table table0)
637 , table0 ~ (constraints :=> columns)
637 , table0 ~ (constraints :=> columns)
638 , table1 ~ (constraints :=> Rename column0 column1 columns) )
638 , table1 ~ (constraints :=> Rename column0 column1 columns) )
639 => Alias column0 -- ^ column to rename
639 => Alias column0 -- ^ column to rename
@@ -645,7 +645,7 @@ renameColumn column0 column1 = UnsafeAlterTable $
645-- | An `alterColumn` alters a single column.
645-- | An `alterColumn` alters a single column.
646alterColumn
646alterColumn
647 :: ( KnownSymbol column
647 :: ( KnownSymbol column
648− , Has tab (TablesOf schema) table0
648+ , Has tab schema ('Table table0)
649 , table0 ~ (constraints :=> columns)
649 , table0 ~ (constraints :=> columns)
650 , Has column columns ty0
650 , Has column columns ty0
651 , tables1 ~ (constraints :=> Alter column ty1 columns))
651 , tables1 ~ (constraints :=> Alter column ty1 columns))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+2−2
@@ -1032,7 +1032,7 @@ newtype Table
1032 = UnsafeTable { renderTable :: ByteString }
1032 = UnsafeTable { renderTable :: ByteString }
1033 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1033 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1034instance
1034instance
1035− ( Has alias (TablesOf schema) table
1035+ ( Has alias schema ('Table table)
1036 , relation ~ ColumnsToRelation (TableToColumns table)
1036 , relation ~ ColumnsToRelation (TableToColumns table)
1037 ) => IsLabel alias (Table schema relation) where
1037 ) => IsLabel alias (Table schema relation) where
1038 fromLabel = UnsafeTable $ renderAlias (Alias @alias)
1038 fromLabel = UnsafeTable $ renderAlias (Alias @alias)
@@ -1045,7 +1045,7 @@ newtype View
1045 = UnsafeView { renderView :: ByteString }
1045 = UnsafeView { renderView :: ByteString }
1046 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1046 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1047instance
1047instance
1048− ( Has alias (ViewsOf schema) columns
1048+ ( Has alias schema ('View columns)
1049 ) => IsLabel alias (View schema columns) where
1049 ) => IsLabel alias (View schema columns) where
1050 fromLabel = UnsafeView $ renderAlias (Alias @alias)
1050 fromLabel = UnsafeView $ renderAlias (Alias @alias)
1051
1051
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+10−10
@@ -213,7 +213,7 @@ INSERT statements
213insertRows
213insertRows
214 :: ( SOP.SListI columns
214 :: ( SOP.SListI columns
215 , SOP.SListI results
215 , SOP.SListI results
216− , Has tab (TablesOf schema) table
216+ , Has tab schema ('Table table)
217 , columns ~ TableToColumns table )
217 , columns ~ TableToColumns table )
218 => Alias tab -- ^ table to insert into
218 => Alias tab -- ^ table to insert into
219 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
219 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -243,7 +243,7 @@ insertRows tab row rows conflict returning = UnsafeManipulation $
243insertRow
243insertRow
244 :: ( SOP.SListI columns
244 :: ( SOP.SListI columns
245 , SOP.SListI results
245 , SOP.SListI results
246− , Has tab (TablesOf schema) table
246+ , Has tab schema ('Table table)
247 , columns ~ TableToColumns table )
247 , columns ~ TableToColumns table )
248 => Alias tab -- ^ table to insert into
248 => Alias tab -- ^ table to insert into
249 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
249 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -256,7 +256,7 @@ insertRow tab row = insertRows tab row []
256-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
256-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
257insertRows_
257insertRows_
258 :: ( SOP.SListI columns
258 :: ( SOP.SListI columns
259− , Has tab (TablesOf schema) table
259+ , Has tab schema ('Table table)
260 , columns ~ TableToColumns table )
260 , columns ~ TableToColumns table )
261 => Alias tab -- ^ table to insert into
261 => Alias tab -- ^ table to insert into
262 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
262 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -268,7 +268,7 @@ insertRows_ tab row rows =
268-- | Insert a single row returning `Nil` and raising an error on conflicts.
268-- | Insert a single row returning `Nil` and raising an error on conflicts.
269insertRow_
269insertRow_
270 :: ( SOP.SListI columns
270 :: ( SOP.SListI columns
271− , Has tab (TablesOf schema) table
271+ , Has tab schema ('Table table)
272 , columns ~ TableToColumns table )
272 , columns ~ TableToColumns table )
273 => Alias tab -- ^ table to insert into
273 => Alias tab -- ^ table to insert into
274 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
274 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -279,7 +279,7 @@ insertRow_ tab row = insertRow tab row OnConflictDoRaise (Returning Nil)
279insertQuery
279insertQuery
280 :: ( SOP.SListI columns
280 :: ( SOP.SListI columns
281 , SOP.SListI results
281 , SOP.SListI results
282− , Has tab (TablesOf schema) table
282+ , Has tab schema ('Table table)
283 , columns ~ TableToColumns table )
283 , columns ~ TableToColumns table )
284 => Alias tab -- ^ table to insert into
284 => Alias tab -- ^ table to insert into
285 -> Query schema params (ColumnsToRelation columns)
285 -> Query schema params (ColumnsToRelation columns)
@@ -296,7 +296,7 @@ insertQuery tab query conflict returning = UnsafeManipulation $
296-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
296-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
297insertQuery_
297insertQuery_
298 :: ( SOP.SListI columns
298 :: ( SOP.SListI columns
299− , Has tab (TablesOf schema) table
299+ , Has tab schema ('Table table)
300 , columns ~ TableToColumns table )
300 , columns ~ TableToColumns table )
301 => Alias tab -- ^ table to insert into
301 => Alias tab -- ^ table to insert into
302 -> Query schema params (ColumnsToRelation columns)
302 -> Query schema params (ColumnsToRelation columns)
@@ -401,7 +401,7 @@ UPDATE statements
401update
401update
402 :: ( SOP.SListI columns
402 :: ( SOP.SListI columns
403 , SOP.SListI results
403 , SOP.SListI results
404− , Has tab (TablesOf schema) table
404+ , Has tab schema ('Table table)
405 , columns ~ TableToColumns table )
405 , columns ~ TableToColumns table )
406 => Alias tab -- ^ table to update
406 => Alias tab -- ^ table to update
407 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
407 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
@@ -431,7 +431,7 @@ update tab columns wh returning = UnsafeManipulation $
431-- | Update a row returning `Nil`.
431-- | Update a row returning `Nil`.
432update_
432update_
433 :: ( SOP.SListI columns
433 :: ( SOP.SListI columns
434− , Has tab (TablesOf schema) table
434+ , Has tab schema ('Table table)
435 , columns ~ TableToColumns table )
435 , columns ~ TableToColumns table )
436 => Alias tab -- ^ table to update
436 => Alias tab -- ^ table to update
437 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
437 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
@@ -448,7 +448,7 @@ DELETE statements
448-- | Delete rows of a table.
448-- | Delete rows of a table.
449deleteFrom
449deleteFrom
450 :: ( SOP.SListI results
450 :: ( SOP.SListI results
451− , Has tab (TablesOf schema) table
451+ , Has tab schema ('Table table)
452 , columns ~ TableToColumns table )
452 , columns ~ TableToColumns table )
453 => Alias tab -- ^ table to delete from
453 => Alias tab -- ^ table to delete from
454 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
454 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
@@ -462,7 +462,7 @@ deleteFrom tab wh returning = UnsafeManipulation $
462
462
463-- | Delete rows returning `Nil`.
463-- | Delete rows returning `Nil`.
464deleteFrom_
464deleteFrom_
465− :: ( Has tab (TablesOf schema) table
465+ :: ( Has tab schema ('Table table)
466 , columns ~ TableToColumns table )
466 , columns ~ TableToColumns table )
467 => Alias tab -- ^ table to delete from
467 => Alias tab -- ^ table to delete from
468 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
468 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+5−5
@@ -68,7 +68,7 @@ Now that we have a couple migrations we can chain them together.
68>>> :{
68>>> :{
69let
69let
70 numMigrations
70 numMigrations
71− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
71+ :: Has "schema_migrations" schema ('Table MigrationsTable)
72 => PQ schema schema IO ()
72 => PQ schema schema IO ()
73 numMigrations = do
73 numMigrations = do
74 result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
74 result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
@@ -283,7 +283,7 @@ type MigrationsTable =
283
283
284-- | Creates a `MigrationsTable` if it does not already exist.
284-- | Creates a `MigrationsTable` if it does not already exist.
285createMigrations
285createMigrations
286− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
286+ :: Has "schema_migrations" schema ('Table MigrationsTable)
287 => Definition schema schema
287 => Definition schema schema
288createMigrations =
288createMigrations =
289 createTableIfNotExists #schema_migrations
289 createTableIfNotExists #schema_migrations
@@ -294,7 +294,7 @@ createMigrations =
294
294
295-- | Inserts a `Migration` into the `MigrationsTable`
295-- | Inserts a `Migration` into the `MigrationsTable`
296insertMigration
296insertMigration
297− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
297+ :: Has "schema_migrations" schema ('Table MigrationsTable)
298 => Manipulation schema '[ 'NotNull 'PGtext] '[]
298 => Manipulation schema '[ 'NotNull 'PGtext] '[]
299insertMigration = insertRow_ #schema_migrations
299insertMigration = insertRow_ #schema_migrations
300 ( Set (param @1) `As` #name :*
300 ( Set (param @1) `As` #name :*
@@ -302,14 +302,14 @@ insertMigration = insertRow_ #schema_migrations
302
302
303-- | Deletes a `Migration` from the `MigrationsTable`
303-- | Deletes a `Migration` from the `MigrationsTable`
304deleteMigration
304deleteMigration
305− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
305+ :: Has "schema_migrations" schema ('Table MigrationsTable)
306 => Manipulation schema '[ 'NotNull 'PGtext ] '[]
306 => Manipulation schema '[ 'NotNull 'PGtext ] '[]
307deleteMigration = deleteFrom_ #schema_migrations (#name .== param @1)
307deleteMigration = deleteFrom_ #schema_migrations (#name .== param @1)
308
308
309-- | Selects a `Migration` from the `MigrationsTable`, returning
309-- | Selects a `Migration` from the `MigrationsTable`, returning
310-- the time at which it was executed.
310-- the time at which it was executed.
311selectMigration
311selectMigration
312− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
312+ :: Has "schema_migrations" schema ('Table MigrationsTable)
313 => Query schema '[ 'NotNull 'PGtext ]
313 => Query schema '[ 'NotNull 'PGtext ]
314 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
314 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
315selectMigration = select
315selectMigration = select
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−14
@@ -102,8 +102,6 @@ module Squeal.PostgreSQL.Schema
102 -- * Schema
102 -- * Schema
103 , SchemumType (..)
103 , SchemumType (..)
104 , SchemaType
104 , SchemaType
105− , TablesOf
106− , ViewsOf
107 , With
105 , With
108 ) where
106 ) where
109
107
@@ -624,18 +622,6 @@ data SchemumType
624
622
625type SchemaType = [(Symbol,SchemumType)]
623type SchemaType = [(Symbol,SchemumType)]
626
624
627−type family TablesOf (schema :: SchemaType) :: TablesType where
628− TablesOf '[] = '[]
629− TablesOf (alias ::: 'Table table ': schema) =
630− alias ::: table ': TablesOf schema
631− TablesOf (_ ': schema) = TablesOf schema
632−
633−type family ViewsOf (schema :: SchemaType) :: RelationsType where
634− ViewsOf '[] = '[]
635− ViewsOf (alias ::: 'View view ': schema) =
636− alias ::: view ': ViewsOf schema
637− ViewsOf (_ ': schema) = ViewsOf schema
638−
639type family With
625type family With
640 (relations :: RelationsType)
626 (relations :: RelationsType)
641 (schema :: SchemaType)
627 (schema :: SchemaType)