on dev help sign in
simplify a bit
commit875f8f83996f645f549312d3ee55b141e94ba217 authorEitan Chatav <eitan.chatav@gmail.com> dateTue 10 Apr 2018, 11:29 (9 years ago) parentb95400d
5 files changed+29−43
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−12 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+10−10 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+5−5 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−14
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−12
@@ -142,7 +142,7 @@ createTable tab columns constraints = UnsafeDefinition $
142142-- :}
143143-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
144144createTableIfNotExists
145− :: ( Has table (TablesOf schema) (constraints :=> columns)
145+ :: ( Has table schema ('Table (constraints :=> columns))
146146 , SOP.SListI columns
147147 , SOP.SListI constraints )
148148 => Alias table -- ^ the name of the table to add
@@ -228,7 +228,7 @@ newtype TableConstraintExpression
228228-- >>> renderDefinition definition
229229-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
230230check
231− :: ( Has alias (TablesOf schema) table
231+ :: ( Has alias schema ('Table table)
232232 , HasAll aliases (TableToColumns table) subcolumns )
233233 => NP Alias aliases
234234 -> (forall tab. Condition '[tab ::: ColumnsToRelation subcolumns] 'Ungrouped '[])
@@ -259,7 +259,7 @@ check _cols condition = UnsafeTableConstraintExpression $
259259-- >>> renderDefinition definition
260260-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
261261unique
262− :: ( Has alias (TablesOf schema) table
262+ :: ( Has alias schema ('Table table)
263263 , HasAll aliases (TableToColumns table) subcolumns )
264264 => NP Alias aliases
265265 -> TableConstraintExpression schema alias ('Unique aliases)
@@ -290,7 +290,7 @@ unique columns = UnsafeTableConstraintExpression $
290290-- >>> renderDefinition definition
291291-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
292292primaryKey
293− :: ( Has alias (TablesOf schema) table
293+ :: ( Has alias schema ('Table table)
294294 , HasAll aliases (TableToColumns table) subcolumns
295295 , AllNotNull subcolumns )
296296 => NP Alias aliases
@@ -401,8 +401,8 @@ type ForeignKeyed schema
401401 columns refcolumns
402402 constraints cols
403403 reftys tys =
404− ( Has child (TablesOf schema) table
405− , Has parent (TablesOf schema) reftable
404+ ( Has child schema ('Table table)
405+ , Has parent schema ('Table reftable)
406406 , HasAll columns (TableToColumns table) tys
407407 , reftable ~ (constraints :=> cols)
408408 , HasAll refcolumns cols reftys
@@ -519,7 +519,7 @@ newtype AlterTable
519519-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
520520addConstraint
521521 :: ( KnownSymbol alias
522− , Has tab (TablesOf schema) table0
522+ , Has tab schema ('Table table0)
523523 , table0 ~ (constraints :=> columns)
524524 , table1 ~ (Create alias constraint constraints :=> columns) )
525525 => Alias alias
@@ -543,7 +543,7 @@ addConstraint alias constraint = UnsafeAlterTable $
543543-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
544544dropConstraint
545545 :: ( KnownSymbol constraint
546− , Has tab (TablesOf schema) table0
546+ , Has tab schema ('Table table0)
547547 , table0 ~ (constraints :=> columns)
548548 , table1 ~ (Drop constraint constraints :=> columns) )
549549 => Alias constraint
@@ -582,7 +582,7 @@ class AddColumn ty where
582582 -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
583583 addColumn
584584 :: ( KnownSymbol column
585− , Has tab (TablesOf schema) table0
585+ , Has tab schema ('Table table0)
586586 , table0 ~ (constraints :=> columns)
587587 , table1 ~ (constraints :=> Create column ty columns) )
588588 => Alias column -- ^ column to add
@@ -611,7 +611,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
611611-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
612612dropColumn
613613 :: ( KnownSymbol column
614− , Has tab (TablesOf schema) table0
614+ , Has tab schema ('Table table0)
615615 , table0 ~ (constraints :=> columns)
616616 , table1 ~ (constraints :=> Drop column columns) )
617617 => Alias column -- ^ column to remove
@@ -633,7 +633,7 @@ dropColumn column = UnsafeAlterTable $
633633renameColumn
634634 :: ( KnownSymbol column0
635635 , KnownSymbol column1
636− , Has tab (TablesOf schema) table0
636+ , Has tab schema ('Table table0)
637637 , table0 ~ (constraints :=> columns)
638638 , table1 ~ (constraints :=> Rename column0 column1 columns) )
639639 => Alias column0 -- ^ column to rename
@@ -645,7 +645,7 @@ renameColumn column0 column1 = UnsafeAlterTable $
645645-- | An `alterColumn` alters a single column.
646646alterColumn
647647 :: ( KnownSymbol column
648− , Has tab (TablesOf schema) table0
648+ , Has tab schema ('Table table0)
649649 , table0 ~ (constraints :=> columns)
650650 , Has column columns ty0
651651 , tables1 ~ (constraints :=> Alter column ty1 columns))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+2−2
@@ -1032,7 +1032,7 @@ newtype Table
10321032 = UnsafeTable { renderTable :: ByteString }
10331033 deriving (GHC.Generic,Show,Eq,Ord,NFData)
10341034instance
1035− ( Has alias (TablesOf schema) table
1035+ ( Has alias schema ('Table table)
10361036 , relation ~ ColumnsToRelation (TableToColumns table)
10371037 ) => IsLabel alias (Table schema relation) where
10381038 fromLabel = UnsafeTable $ renderAlias (Alias @alias)
@@ -1045,7 +1045,7 @@ newtype View
10451045 = UnsafeView { renderView :: ByteString }
10461046 deriving (GHC.Generic,Show,Eq,Ord,NFData)
10471047instance
1048− ( Has alias (ViewsOf schema) columns
1048+ ( Has alias schema ('View columns)
10491049 ) => IsLabel alias (View schema columns) where
10501050 fromLabel = UnsafeView $ renderAlias (Alias @alias)
10511051
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+10−10
@@ -213,7 +213,7 @@ INSERT statements
213213insertRows
214214 :: ( SOP.SListI columns
215215 , SOP.SListI results
216− , Has tab (TablesOf schema) table
216+ , Has tab schema ('Table table)
217217 , columns ~ TableToColumns table )
218218 => Alias tab -- ^ table to insert into
219219 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -243,7 +243,7 @@ insertRows tab row rows conflict returning = UnsafeManipulation $
243243insertRow
244244 :: ( SOP.SListI columns
245245 , SOP.SListI results
246− , Has tab (TablesOf schema) table
246+ , Has tab schema ('Table table)
247247 , columns ~ TableToColumns table )
248248 => Alias tab -- ^ table to insert into
249249 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -256,7 +256,7 @@ insertRow tab row = insertRows tab row []
256256-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
257257insertRows_
258258 :: ( SOP.SListI columns
259− , Has tab (TablesOf schema) table
259+ , Has tab schema ('Table table)
260260 , columns ~ TableToColumns table )
261261 => Alias tab -- ^ table to insert into
262262 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -268,7 +268,7 @@ insertRows_ tab row rows =
268268-- | Insert a single row returning `Nil` and raising an error on conflicts.
269269insertRow_
270270 :: ( SOP.SListI columns
271− , Has tab (TablesOf schema) table
271+ , Has tab schema ('Table table)
272272 , columns ~ TableToColumns table )
273273 => Alias tab -- ^ table to insert into
274274 -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
@@ -279,7 +279,7 @@ insertRow_ tab row = insertRow tab row OnConflictDoRaise (Returning Nil)
279279insertQuery
280280 :: ( SOP.SListI columns
281281 , SOP.SListI results
282− , Has tab (TablesOf schema) table
282+ , Has tab schema ('Table table)
283283 , columns ~ TableToColumns table )
284284 => Alias tab -- ^ table to insert into
285285 -> Query schema params (ColumnsToRelation columns)
@@ -296,7 +296,7 @@ insertQuery tab query conflict returning = UnsafeManipulation $
296296-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
297297insertQuery_
298298 :: ( SOP.SListI columns
299− , Has tab (TablesOf schema) table
299+ , Has tab schema ('Table table)
300300 , columns ~ TableToColumns table )
301301 => Alias tab -- ^ table to insert into
302302 -> Query schema params (ColumnsToRelation columns)
@@ -401,7 +401,7 @@ UPDATE statements
401401update
402402 :: ( SOP.SListI columns
403403 , SOP.SListI results
404− , Has tab (TablesOf schema) table
404+ , Has tab schema ('Table table)
405405 , columns ~ TableToColumns table )
406406 => Alias tab -- ^ table to update
407407 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
@@ -431,7 +431,7 @@ update tab columns wh returning = UnsafeManipulation $
431431-- | Update a row returning `Nil`.
432432update_
433433 :: ( SOP.SListI columns
434− , Has tab (TablesOf schema) table
434+ , Has tab schema ('Table table)
435435 , columns ~ TableToColumns table )
436436 => Alias tab -- ^ table to update
437437 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
@@ -448,7 +448,7 @@ DELETE statements
448448-- | Delete rows of a table.
449449deleteFrom
450450 :: ( SOP.SListI results
451− , Has tab (TablesOf schema) table
451+ , Has tab schema ('Table table)
452452 , columns ~ TableToColumns table )
453453 => Alias tab -- ^ table to delete from
454454 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
@@ -462,7 +462,7 @@ deleteFrom tab wh returning = UnsafeManipulation $
462462
463463-- | Delete rows returning `Nil`.
464464deleteFrom_
465− :: ( Has tab (TablesOf schema) table
465+ :: ( Has tab schema ('Table table)
466466 , columns ~ TableToColumns table )
467467 => Alias tab -- ^ table to delete from
468468 -> 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.
6868>>> :{
6969let
7070 numMigrations
71− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
71+ :: Has "schema_migrations" schema ('Table MigrationsTable)
7272 => PQ schema schema IO ()
7373 numMigrations = do
7474 result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
@@ -283,7 +283,7 @@ type MigrationsTable =
283283
284284-- | Creates a `MigrationsTable` if it does not already exist.
285285createMigrations
286− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
286+ :: Has "schema_migrations" schema ('Table MigrationsTable)
287287 => Definition schema schema
288288createMigrations =
289289 createTableIfNotExists #schema_migrations
@@ -294,7 +294,7 @@ createMigrations =
294294
295295-- | Inserts a `Migration` into the `MigrationsTable`
296296insertMigration
297− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
297+ :: Has "schema_migrations" schema ('Table MigrationsTable)
298298 => Manipulation schema '[ 'NotNull 'PGtext] '[]
299299insertMigration = insertRow_ #schema_migrations
300300 ( Set (param @1) `As` #name :*
@@ -302,14 +302,14 @@ insertMigration = insertRow_ #schema_migrations
302302
303303-- | Deletes a `Migration` from the `MigrationsTable`
304304deleteMigration
305− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
305+ :: Has "schema_migrations" schema ('Table MigrationsTable)
306306 => Manipulation schema '[ 'NotNull 'PGtext ] '[]
307307deleteMigration = deleteFrom_ #schema_migrations (#name .== param @1)
308308
309309-- | Selects a `Migration` from the `MigrationsTable`, returning
310310-- the time at which it was executed.
311311selectMigration
312− :: Has "schema_migrations" (TablesOf schema) MigrationsTable
312+ :: Has "schema_migrations" schema ('Table MigrationsTable)
313313 => Query schema '[ 'NotNull 'PGtext ]
314314 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
315315selectMigration = select
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−14
@@ -102,8 +102,6 @@ module Squeal.PostgreSQL.Schema
102102 -- * Schema
103103 , SchemumType (..)
104104 , SchemaType
105− , TablesOf
106− , ViewsOf
107105 , With
108106 ) where
109107
@@ -624,18 +622,6 @@ data SchemumType
624622
625623type SchemaType = [(Symbol,SchemumType)]
626624
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−
639625type family With
640626 (relations :: RelationsType)
641627 (schema :: SchemaType)