on dev help sign in
SchemaHasTable
commite50f0a0101720010e2dfc9aa0667b6fd75e8a51d authorEitan Chatav <eitan.chatav@gmail.com> dateFri 8 Dec 2017, 11:38 (9 years ago) parent8bf3c62
3 files changed+16−4
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+6−3
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+1−1
@@ -238,7 +238,7 @@ primaryKey columns = UnsafeTableConstraint $
238238-- :}
239239-- "CREATE TABLE users (id serial, username text NOT NULL, PRIMARY KEY (id)); CREATE TABLE emails (id serial, userid integer NOT NULL, email text NOT NULL, PRIMARY KEY (id), FOREIGN KEY (userid) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT);"
240240foreignKey
241− :: ( HasTable tab (UnconstrainOver schema) refcolumns
241+ :: ( SchemaHasTable tab schema refcolumns
242242 , SameTypes subcolumns refsubcolumns
243243 , AllNotNull subcolumns
244244 , SOP.SListI subcolumns
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9
@@ -105,6 +105,7 @@ module Squeal.PostgreSQL.Expression
105105 -- * Tables
106106 , Table (UnsafeTable, renderTable)
107107 , HasTable (getTable)
108+ , SchemaHasTable
108109 -- * TypeExpression
109110 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
110111 , PGTyped (pgtype)
@@ -998,6 +999,14 @@ instance HasTable table schema columns
998999 => IsLabel table (Table schema columns) where
9991000 fromLabel = getTable (Alias @table)
10001001
1002+type family SchemaHasTable
1003+ (table :: Symbol)
1004+ (schema :: SchemaType)
1005+ (columns :: ColumnsType)
1006+ where
1007+ SchemaHasTable table schema columns =
1008+ HasTable table (UnconstrainOver schema) columns
1009+
10011010{-----------------------------------------
10021011type expressions
10031012-----------------------------------------}
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+6−3
@@ -178,7 +178,8 @@ in renderManipulation manipulation
178178"INSERT INTO tab (col1, col2) VALUES (2, 4), (6, 8) ON CONFLICT DO UPDATE SET col1 = 2 WHERE (col1 = col2) RETURNING (col1 + col2) AS sum;"
179179-}
180180insertInto
181− :: (SOP.SListI columns, SOP.SListI results, HasTable table (UnconstrainOver schema) columns)
181+ :: ( SOP.SListI columns, SOP.SListI results
182+ , SchemaHasTable table schema columns )
182183 => Alias table -- ^ table to insert into
183184 -> ValuesClause schema params columns -- ^ values to insert
184185 -> ConflictClause columns params
@@ -302,7 +303,9 @@ UPDATE statements
302303-- :}
303304-- "UPDATE tab SET col1 = 2 WHERE (col1 <> col2);"
304305update
305− :: (HasTable table (UnconstrainOver schema) columns, SOP.SListI columns, SOP.SListI results)
306+ :: ( SchemaHasTable table schema columns
307+ , SOP.SListI columns
308+ , SOP.SListI results )
306309 => Alias table -- ^ table to update
307310 -> NP (Aliased (UpdateExpression columns params)) columns
308311 -- ^ modified values to replace old values
@@ -357,7 +360,7 @@ DELETE statements
357360-- :}
358361-- "DELETE FROM tab WHERE (col1 = col2) RETURNING *;"
359362deleteFrom
360− :: (SOP.SListI results, HasTable table (UnconstrainOver schema) columns)
363+ :: (SOP.SListI results, SchemaHasTable table schema columns)
361364 => Alias table -- ^ table to delete from
362365 -> Condition '[table ::: columns] 'Ungrouped params
363366 -- ^ condition under which to delete a row