@@ -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