on dev help sign in
fix tests
commitca38686cef756baa6b65e9382ca58722b4be566d authorEitan Chatav <eitan.chatav@gmail.com> dateTue 4 Dec 2018, 00:01 (8 years ago) parent2bef1d3
9 files changed+77−104
squeal-postgresql/exe/Example.hs+5−7 squeal-postgresql/src/Squeal/PostgreSQL.hs+6−5 squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+5−5 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+15−16 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9−9 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+24−52 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+2−2 squeal-postgresql/test/Specs/ExceptionHandling.hs+9−6
squeal-postgresql/exe/Example.hs+5−7
@@ -6,8 +6,6 @@
66 , OverloadedStrings
77 , OverloadedLists
88 , TypeApplications
9− , TypeFamilies
10− , TypeInType
119 , TypeOperators
1210#-}
1311
@@ -43,11 +41,11 @@ type Schema =
4341 ])
4442 ]
4543
46−type family Schemas0 :: SchemasType where Schemas0 = '["public" ::: '[]]
47−type family Schemas :: SchemasType where Schemas = '["public" ::: Schema]
48−type DB = '[] :=> Schemas
44+type Schemas = Public Schema
4945
50−setup :: Definition Schemas0 Schemas
46+type DB = DBof Schemas
47+
48+setup :: Definition (Public '[]) Schemas
5149setup =
5250 createTable #users
5351 ( serial `as` #id :*
@@ -63,7 +61,7 @@ setup =
6361 foreignKey #user_id #users #id
6462 OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
6563
66−teardown :: Definition Schemas Schemas0
64+teardown :: Definition Schemas (Public '[])
6765teardown = dropTable #emails >>> dropTable #users
6866
6967insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
squeal-postgresql/src/Squeal/PostgreSQL.hs+6−5
@@ -46,7 +46,8 @@ type EmailsConstraints =
4646type Schema =
4747 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
4848 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
49−type DB = '[ "public" ::: Schema ]
49+type Schemas = Public Schema
50+type DB = DBof Schemas
5051:}
5152
5253Notice the use of type operators.
@@ -68,7 +69,7 @@ labels to refer to named tables and columns in our schema.
6869
6970>>> :{
7071let
71− setup :: Definition '["public" ::: '[]] DB
72+ setup :: Definition (Public '[]) Schemas
7273 setup =
7374 createTable #users
7475 ( serial `as` #id :*
@@ -89,14 +90,14 @@ We can easily see the generated SQL is unsurprising looking.
8990CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
9091CREATE TABLE "emails" ("id" serial, "user_id" int NOT NULL, "email" text NULL, CONSTRAINT "pk_emails" PRIMARY KEY ("id"), CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
9192
92−Notice that @setup@ starts with an empty public schema @'["public" ::: '[]]@ and produces @DB@.
93+Notice that @setup@ starts with an empty public schema @(Public '[])@ and produces @Schemas@.
9394In our `createTable` commands we included `TableConstraint`s to define
9495primary and foreign keys, making them somewhat complex. Our @teardown@
9596`Definition` is simpler.
9697
9798>>> :{
9899let
99− teardown :: Definition DB '["public" ::: '[]]
100+ teardown :: Definition Schemas (Public '[])
100101 teardown = dropTable #emails >>> dropTable #users
101102:}
102103
@@ -190,7 +191,7 @@ transformer and when the schema doesn't change we can use `Monad` and
190191
191192>>> :{
192193let
193− session :: PQ DB DB IO ()
194+ session :: PQ Schemas Schemas IO ()
194195 session = do
195196 idResults <- traversePrepared insertUser (Only . userName <$> users)
196197 ids <- traverse (fmap fromOnly . getRow 0) idResults
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+5−5
@@ -27,7 +27,7 @@ round trip query.
2727>>> instance HasDatatypeInfo Row
2828>>> :{
2929let
30− roundTrip :: Query '[] (TuplePG Row) (RowPG Row)
30+ roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
3131 roundTrip = values_ $
3232 parameter @1 int2 `as` #col1 :*
3333 parameter @2 text `as` #col2 :*
@@ -68,7 +68,7 @@ Once again, we define a simple round trip query.
6868
6969>>> :{
7070let
71− roundTrip :: Query '[] (TuplePG Row) (RowPG Row)
71+ roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
7272 roundTrip = values_ $
7373 parameter @1 (int2 & vararray) `as` #col1 :*
7474 parameter @2 (int2 & fixarray @2) `as` #col2 :*
@@ -114,7 +114,7 @@ type Schema =
114114
115115>>> :{
116116let
117− setup :: Definition '["public" ::: '[]] '["public" ::: Schema]
117+ setup :: Definition (Public '[]) (Public Schema)
118118 setup =
119119 createTypeEnumFrom @Schwarma #schwarma >>>
120120 createTypeCompositeFrom @Person #person
@@ -146,7 +146,7 @@ Once again, define a round trip query.
146146
147147>>> :{
148148let
149− roundTrip :: Query '["public" ::: Schema] (TuplePG Row) (RowPG Row)
149+ roundTrip :: Query (DBof (Public Schema)) (TuplePG Row) (RowPG Row)
150150 roundTrip = values_ $
151151 parameter @1 (typedef #schwarma) `as` #schwarma :*
152152 parameter @2 (typedef #person) `as` #person1 :*
@@ -157,7 +157,7 @@ Finally, we can drop our type definitions.
157157
158158>>> :{
159159let
160− teardown :: Definition '["public" ::: Schema] '["public" ::: '[]]
160+ teardown :: Definition (Public Schema) (Public '[])
161161 teardown = dropType #schwarma >>> dropType #person
162162:}
163163
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+15−16
@@ -153,7 +153,7 @@ type Table = '[] :=>
153153
154154>>> :{
155155let
156− setup :: Definition '["public" ::: '[]] '["public" ::: '["tab" ::: 'Table Table]]
156+ setup :: Definition (Public '[]) (Public '["tab" ::: 'Table Table])
157157 setup = createTable #tab
158158 (nullable int `as` #a :* nullable real `as` #b) Nil
159159in printSQL setup
@@ -189,11 +189,11 @@ type Table = '[] :=>
189189 , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]
190190:}
191191
192−>>> type DB = '["public" ::: '["tab" ::: 'Table Table]]
192+>>> type Schemas = Public '["tab" ::: 'Table Table]
193193
194194>>> :{
195195let
196− setup :: Definition DB DB
196+ setup :: Definition Schemas Schemas
197197 setup = createTableIfNotExists #tab
198198 (nullable int `as` #a :* nullable real `as` #b) Nil
199199in printSQL setup
@@ -280,7 +280,7 @@ type Schema = '[
280280
281281>>> :{
282282let
283− definition :: Definition '["public" ::: '[]] '["public" ::: Schema]
283+ definition :: Definition (Public '[]) (Public Schema)
284284 definition = createTable #tab
285285 ( (int & notNullable) `as` #a :*
286286 (int & notNullable) `as` #b )
@@ -315,7 +315,7 @@ type Schema = '[
315315
316316>>> :{
317317let
318− definition :: Definition '["public" ::: '[]] '["public" ::: Schema]
318+ definition :: Definition (Public '[]) (Public Schema)
319319 definition = createTable #tab
320320 ( (int & nullable) `as` #a :*
321321 (int & nullable) `as` #b )
@@ -345,12 +345,11 @@ type Schema = '[
345345 "id" ::: 'Def :=> 'NotNull 'PGint4,
346346 "name" ::: 'NoDef :=> 'NotNull 'PGtext
347347 ])]
348−type DB = '["public" ::: Schema]
349348:}
350349
351350>>> :{
352351let
353− definition :: Definition '["public" ::: '[]] DB
352+ definition :: Definition (Public '[]) (Public Schema)
354353 definition = createTable #tab
355354 ( serial `as` #id :*
356355 (text & notNullable) `as` #name )
@@ -396,7 +395,7 @@ type Schema =
396395
397396>>> :{
398397let
399− setup :: Definition '["public" ::: '[]] '["public" ::: Schema]
398+ setup :: Definition (Public '[]) (Public Schema)
400399 setup =
401400 createTable #users
402401 ( serial `as` #id :*
@@ -431,7 +430,7 @@ type Schema =
431430
432431>>> :{
433432let
434− setup :: Definition '["public" ::: '[]] '["public" ::: Schema]
433+ setup :: Definition (Public '[]) (Public Schema)
435434 setup =
436435 createTable #employees
437436 ( serial `as` #id :*
@@ -534,7 +533,7 @@ DROP statements
534533--
535534-- >>> :{
536535-- let
537−-- definition :: Definition '["public" ::: '["muh_table" ::: 'Table t]] '["public" ::: '[]]
536+-- definition :: Definition '["public" ::: '["muh_table" ::: 'Table t]] (Public '[])
538537-- definition = dropTable #muh_table
539538-- :}
540539--
@@ -870,7 +869,7 @@ dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
870869
871870-- | Enumerated types are created using the `createTypeEnum` command, for example
872871--
873−-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition '["public" ::: '[]] '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
872+-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition (Public '[]) '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
874873-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
875874createTypeEnum
876875 :: (KnownSymbol enum, Has sch schemas schema, SOP.All KnownSymbol labels)
@@ -890,7 +889,7 @@ createTypeEnum enum labels = UnsafeDefinition $
890889-- >>> instance SOP.HasDatatypeInfo Schwarma
891890-- >>> :{
892891-- let
893−-- createSchwarma :: Definition '["public" ::: '[]] '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]]
892+-- createSchwarma :: Definition (Public '[]) '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]]
894893-- createSchwarma = createTypeEnumFrom @Schwarma #schwarma
895894-- in
896895-- printSQL createSchwarma
@@ -919,7 +918,7 @@ type PGcomplex = 'PGcomposite
919918
920919>>> :{
921920let
922− setup :: Definition '["public" ::: '[]] '["public" ::: '["complex" ::: 'Typedef PGcomplex]]
921+ setup :: Definition (Public '[]) '["public" ::: '["complex" ::: 'Typedef PGcomplex]]
923922 setup = createTypeComposite #complex
924923 (float8 `as` #real :* float8 `as` #imaginary)
925924in printSQL setup
@@ -946,10 +945,10 @@ createTypeComposite ty fields = UnsafeDefinition $
946945-- >>> data Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Generic
947946-- >>> instance SOP.Generic Complex
948947-- >>> instance SOP.HasDatatypeInfo Complex
949−-- >>> type DB = '["public" ::: '["complex" ::: 'Typedef (PG (Composite Complex))]]
948+-- >>> type Schema = '["complex" ::: 'Typedef (PG (Composite Complex))]
950949-- >>> :{
951950-- let
952−-- createComplex :: Definition '["public" ::: '[]] DB
951+-- createComplex :: Definition (Public '[]) (Public Schema)
953952-- createComplex = createTypeCompositeFrom @Complex #complex
954953-- in
955954-- printSQL createComplex
@@ -978,7 +977,7 @@ instance (KnownSymbol alias, PGTyped schemas ty)
978977-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
979978-- >>> instance SOP.Generic Schwarma
980979-- >>> instance SOP.HasDatatypeInfo Schwarma
981−-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] '["public" ::: '[]])
980+-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] (Public '[]))
982981-- DROP TYPE "schwarma";
983982dropType
984983 :: (Has sch schemas schema, Has td schema ('Typedef ty))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9−9
@@ -243,7 +243,7 @@ class KnownNat n => HasParameter
243243 | n params -> ty where
244244 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
245245 --
246− -- >>> let expr = parameter @1 int4 :: Expression db from grp '[ 'Null 'PGint4] ('Null 'PGint4)
246+ -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
247247 -- >>> printSQL expr
248248 -- ($1 :: int4)
249249 parameter
@@ -259,14 +259,14 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
259259-- | `param` takes a `Nat` using type application and for basic types,
260260-- infers a `TypeExpression`.
261261--
262−-- >>> let expr = param @1 :: Expression db from grp '[ 'Null 'PGint4] ('Null 'PGint4)
262+-- >>> let expr = param @1 :: Expression (commons :=> schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
263263-- >>> printSQL expr
264264-- ($1 :: int4)
265265param
266− :: forall n commons schemas params from grouping ty
267− . (PGTyped schemas ty, HasParameter n params ty)
268− => Expression (commons :=> schemas) from grouping params ty -- ^ param
269−param = parameter @n pgtype
266+ :: forall n db commons schemas params from grouping ty
267+ . (db ~ (commons :=> schemas), PGTyped schemas ty, HasParameter n params ty)
268+ => Expression db from grouping params ty -- ^ param
269+param = parameter @n (pgtype @schemas)
270270
271271instance (HasUnique table from columns, Has column columns ty)
272272 => IsLabel column (Expression db from 'Ungrouped params ty) where
@@ -418,7 +418,7 @@ matchNull y f x = ifThenElse (isNull x) y
418418`nullIf` gives @NULL@.
419419
420420>>> :set -XTypeApplications -XDataKinds
421−>>> let expr = nullIf false (param @1) :: Expression db from grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
421+>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) from grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
422422>>> printSQL expr
423423NULL IF (FALSE, ($1 :: bool))
424424-}
@@ -478,7 +478,7 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
478478-- '[ "real" ::: 'NotNull 'PGfloat8
479479-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
480480-- type Schema = '["complex" ::: 'Typedef Complex]
481−-- type DB = '["public" ::: Schema]
481+-- type DB = DBof (Public Schema)
482482-- :}
483483--
484484-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
@@ -505,7 +505,7 @@ instance Monoid
505505 mempty = array []
506506 mappend = (<>)
507507
508−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression sch rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
508+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
509509-- >>> printSQL expr
510510-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
511511greatest
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+24−52
@@ -62,12 +62,12 @@ A `Query` is also considered a `Manipulation` even though it does not modify dat
6262
6363simple insert:
6464
65+>>> type Columns = '["col1" ::: 'NoDef :=> 'Null 'PGint4, "col2" ::: 'Def :=> 'NotNull 'PGint4]
66+>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
67+>>> type Schemas = (Public Schema)
6568>>> :{
6669let
67− manipulation :: Manipulation
68− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
69− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
70− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])]] '[] '[]
70+ manipulation :: Manipulation (DBof Schemas) '[] '[]
7171 manipulation =
7272 insertRow_ #tab (Set 2 `as` #col1 :* Default `as` #col2)
7373in printSQL manipulation
@@ -76,13 +76,11 @@ INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT)
7676
7777parameterized insert:
7878
79+>>> type Columns = '["col1" ::: 'NoDef :=> 'NotNull 'PGint4, "col2" ::: 'NoDef :=> 'NotNull 'PGint4]
80+>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
7981>>> :{
8082let
81− manipulation :: Manipulation
82− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
83− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
84− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]]
85− '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
83+ manipulation :: Manipulation (DBof (Public Schema)) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
8684 manipulation =
8785 insertRow_ #tab
8886 (Set (param @1) `as` #col1 :* Set (param @2) `as` #col2)
@@ -94,27 +92,21 @@ returning insert:
9492
9593>>> :{
9694let
97− manipulation :: Manipulation
98− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
99− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
100− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])]] '[]
101− '["fromOnly" ::: 'NotNull 'PGint4]
95+ manipulation :: Manipulation (DBof (Public Schema)) '[] '["fromOnly" ::: 'NotNull 'PGint4]
10296 manipulation =
103− insertRow #tab (Set 2 `as` #col1 :* Default `as` #col2)
97+ insertRow #tab (Set 2 `as` #col1 :* Set 3 `as` #col2)
10498 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
10599in printSQL manipulation
106100:}
107−INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT) RETURNING "col1" AS "fromOnly"
101+INSERT INTO "tab" ("col1", "col2") VALUES (2, 3) RETURNING "col1" AS "fromOnly"
108102
109103upsert:
110104
105+>>> type Columns = '["col1" ::: 'NoDef :=> 'NotNull 'PGint4, "col2" ::: 'NoDef :=> 'NotNull 'PGint4]
106+>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
111107>>> :{
112108let
113− manipulation :: Manipulation
114− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
115− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
116− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]]
117− '[] '[ "sum" ::: 'NotNull 'PGint4]
109+ manipulation :: Manipulation (DBof (Public Schema)) '[] '[ "sum" ::: 'NotNull 'PGint4]
118110 manipulation =
119111 insertRows #tab
120112 (Set 2 `as` #col1 :* Set 4 `as` #col2)
@@ -131,31 +123,17 @@ query insert:
131123
132124>>> :{
133125let
134− manipulation :: Manipulation
135− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
136− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
137− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
138− ])
139− , "other_tab" ::: 'Table ('[] :=>
140− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
141− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
142− ])
143− ]] '[] '[]
144− manipulation =
145− insertQuery_ #tab
146− (selectStar (from (table (#other_tab `as` #t))))
126+ manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
127+ manipulation = insertQuery_ #tab (selectStar (from (table #tab)))
147128in printSQL manipulation
148129:}
149−INSERT INTO "tab" SELECT * FROM "other_tab" AS "t"
130+INSERT INTO "tab" SELECT * FROM "tab" AS "tab"
150131
151132update:
152133
153134>>> :{
154135let
155− manipulation :: Manipulation
156− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
157− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
158− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]] '[] '[]
136+ manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
159137 manipulation =
160138 update_ #tab (Set 2 `as` #col1 :* Same `as` #col2)
161139 (#col1 ./= #col2)
@@ -167,10 +145,7 @@ delete:
167145
168146>>> :{
169147let
170− manipulation :: Manipulation
171− '[ "public" ::: '["tab" ::: 'Table ('[] :=>
172− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
173− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]] '[]
148+ manipulation :: Manipulation (DBof (Public Schema)) '[]
174149 '[ "col1" ::: 'NotNull 'PGint4
175150 , "col2" ::: 'NotNull 'PGint4 ]
176151 manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStar
@@ -180,20 +155,17 @@ DELETE FROM "tab" WHERE ("col1" = "col2") RETURNING *
180155
181156with manipulation:
182157
183−>>> type ProductsTable = '[] :=> '["product" ::: 'NoDef :=> 'NotNull 'PGtext, "date" ::: 'Def :=> 'NotNull 'PGdate]
184−
158+>>> type ProductsColumns = '["product" ::: 'NoDef :=> 'NotNull 'PGtext, "date" ::: 'Def :=> 'NotNull 'PGdate]
159+>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
185160>>> :{
186161let
187− manipulation :: Manipulation
188− '[ "public" ::: '["products" ::: 'Table ProductsTable
189− , "products_deleted" ::: 'Table ProductsTable
190− ]] '[ 'NotNull 'PGdate] '[]
162+ manipulation :: Manipulation (DBof (Public ProductsSchema)) '[ 'NotNull 'PGdate] '[]
191163 manipulation = with
192− (CommonTableExpression (deleteFrom #products (#date .< param @1) ReturningStar `as` #deleted_rows) :>> Done)
193− (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `as` #t)))))
164+ (deleteFrom #products (#date .< param @1) ReturningStar `as` #del)
165+ (insertQuery_ #products_deleted (selectStar (from (common (#del)))))
194166in printSQL manipulation
195167:}
196−WITH "deleted_rows" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *) INSERT INTO "products_deleted" SELECT * FROM "deleted_rows" AS "t"
168+WITH "del" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *) INSERT INTO "products_deleted" SELECT * FROM "del" AS "del"
197169-}
198170
199171newtype Manipulation
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+2−2
@@ -31,7 +31,7 @@ type EmailsTable =
3131
3232>>> :{
3333let
34− makeUsers :: Migration IO '["public" ::: '[]] '["public" ::: '["users" ::: 'Table UsersTable]]
34+ makeUsers :: Migration IO (Public '[]) '["public" ::: '["users" ::: 'Table UsersTable]]
3535 makeUsers = Migration
3636 { name = "make users table"
3737 , up = void . define $
@@ -77,7 +77,7 @@ let
7777:}
7878
7979>>> :{
80−withConnection "host=localhost port=5432 schemasname=exampleschemas" $
80+withConnection "host=localhost port=5432 dbname=exampledb" $
8181 manipulate (UnsafeManipulation "SET client_min_messages TO WARNING;")
8282 -- suppress notices
8383 & pqThen (migrateUp migrations)
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+2−2
@@ -124,7 +124,7 @@ To specify the schema you wish to connect with, use type application.
124124>>> type Schema = '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint2]]
125125>>> :set -XTypeApplications
126126>>> :set -XOverloadedStrings
127−>>> conn <- connectdbs @Schema "host=localhost port=5432 schemasname=exampleschemas"
127+>>> conn <- connectdb @Schema "host=localhost port=5432 dbname=exampledb"
128128
129129Note that, for now, squeal doesn't offer any protection from connecting
130130with the wrong schema!
@@ -140,7 +140,7 @@ connectdb = fmap K . liftBase . LibPQ.connectdb
140140finish :: MonadBase IO io => K LibPQ.Connection schemas -> io ()
141141finish = liftBase . LibPQ.finish . unK
142142
143−-- | Do `connectdbs` and `finish` before and after a computation.
143+-- | Do `connectdb` and `finish` before and after a computation.
144144withConnection
145145 :: forall schemas0 schemas1 io x
146146 . MonadBaseControl IO io
squeal-postgresql/test/Specs/ExceptionHandling.hs+9−6
@@ -7,6 +7,7 @@
77{-# LANGUAGE OverloadedStrings #-}
88{-# LANGUAGE TypeApplications #-}
99{-# LANGUAGE TypeFamilies #-}
10+{-# LANGUAGE TypeInType #-}
1011{-# LANGUAGE TypeOperators #-}
1112module ExceptionHandling
1213 ( specs
@@ -45,7 +46,9 @@ type Schema =
4546 ])
4647 ]
4748
48−type DB = '["public" ::: Schema]
49+type Schemas = Public Schema
50+
51+type DB = DBof Schemas
4952
5053data User =
5154 User { userName :: Text
@@ -61,7 +64,7 @@ insertUser = insertRows #users
6164 (Default `as` #id :* Set (param @1) `as` #name :* Set (param @2) `as` #vec) []
6265 OnConflictDoRaise (Returning (#id `as` #fromOnly))
6366
64−setup :: Definition '["public" ::: '[]] DB
67+setup :: Definition (Public '[]) Schemas
6568setup =
6669 createTable #users
6770 ( serial `as` #id :*
@@ -78,10 +81,10 @@ setup =
7881 foreignKey #user_id #users #id
7982 OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
8083
81−teardown :: Definition DB '["public" ::: '[]]
84+teardown :: Definition Schemas (Public '[])
8285teardown = dropTable #emails >>> dropTable #users
8386
84−migration :: Migration IO '["public" ::: '[]] DB
87+migration :: Migration IO (Public '[]) Schemas
8588migration = Migration { name = "test"
8689 , up = void $ define setup
8790 , down = void $ define teardown }
@@ -100,10 +103,10 @@ connectionString = "host=localhost port=5432 dbname=exampledb"
100103testUser :: User
101104testUser = User "TestUser" Nothing []
102105
103−newUser :: (MonadBase IO m, MonadPQ DB m) => User -> m ()
106+newUser :: (MonadBase IO m, MonadPQ Schemas m) => User -> m ()
104107newUser u = void $ manipulateParams insertUser (userName u, userVec u)
105108
106−insertUserTwice :: (MonadBase IO m, MonadPQ DB m) => m ()
109+insertUserTwice :: (MonadBase IO m, MonadPQ Schemas m) => m ()
107110insertUserTwice = newUser testUser >> newUser testUser
108111
109112specs :: SpecWith ()