@@ -14,6 +14,7 @@
1414
1515module Squeel.PostgreSQL.Statement where
1616
17+import Control.Category
1718import Data.Boolean
1819import Data.ByteString (ByteString)
1920import Data.Maybe
@@ -24,16 +25,22 @@ import Data.Vinyl.Functor
2425import GHC.Exts
2526import GHC.OverloadedLabels
2627import GHC.TypeLits
28+import Prelude hiding (id,(.))
2729
2830import qualified Data.ByteString as ByteString
2931
3032import Squeel.PostgreSQL.Schema
3133
34+{-----------------------------------------
35+column expressions
36+-----------------------------------------}
37+
3238newtype Expression
33− (params :: [NullityType])
34− (tables :: [(Symbol,[(Symbol,NullityType)])])
35− (ty :: NullityType)
36− = UnsafeExpression { renderExpression :: ByteString }
39+ (params :: [ColumnType])
40+ (tables :: [(Symbol,[(Symbol,ColumnType)])])
41+ (ty :: ColumnType)
42+ = UnsafeExpression { renderExpression :: ByteString }
43+ deriving (Show,Eq)
3744
3845class KnownNat n => HasParameter (n :: Nat) params ty | n params -> ty where
3946 param :: Proxy# n -> Expression params tables ty
@@ -58,7 +65,7 @@ class KnownSymbol column => HasColumn column columns ty
5865 getColumn :: Proxy# column -> Expression params '[table ::: columns] ty
5966 getColumn column = UnsafeExpression $ fromString $ symbolVal' column
6067instance {-# OVERLAPPING #-} KnownSymbol column
61− => HasColumn column ((column ::: ty) ': tys) ty
68+ => HasColumn column ((column ::: optionality ty) ': tys) ('Required ty)
6269instance {-# OVERLAPPABLE #-} (KnownSymbol column, HasColumn column table ty)
6370 => HasColumn column (ty' ': table) ty
6471
@@ -66,14 +73,31 @@ instance (HasColumn column columns ty, tables ~ '[table ::: columns])
6673 => IsLabel column (Expression params tables ty) where
6774 fromLabel = getColumn
6875
69−(.&.)
76+(&.)
7077 :: (HasTable table tables columns, HasColumn column columns ty)
7178 => Alias table -> Alias column -> Expression params tables ty
72−Alias table .&. Alias column = UnsafeExpression $
79+Alias table &. Alias column = UnsafeExpression $
7380 fromString (symbolVal' table)
7481 <> "." <>
7582 fromString (symbolVal' column)
7683
84+def :: Expression params '[] ('Optional (nullity ty))
85+def = UnsafeExpression "DEFAULT"
86+
87+null :: Expression params tables (optionality ('Null ty))
88+null = UnsafeExpression "NULL"
89+
90+coalesce
91+ :: [Expression params tables ('Required ('Null x))]
92+ -> Expression params tables ('Required ('NotNull x))
93+ -> Expression params tables ('Required ('NotNull x))
94+coalesce nulls isn'tNull = UnsafeExpression $ mconcat
95+ [ "COALESCE("
96+ , ByteString.intercalate ", " $ map renderExpression nulls
97+ , ", ", renderExpression isn'tNull
98+ , ")"
99+ ]
100+
77101unsafeBinaryOp
78102 :: ByteString
79103 -> Expression params tables ty0
@@ -96,7 +120,7 @@ unsafeFunction
96120unsafeFunction fn x = UnsafeExpression $ mconcat
97121 [fn, "(", renderExpression x, ")"]
98122
99−instance PGNum ty => Num (Expression params tables (nullity ty)) where
123+instance PGNum ty => Num (Expression params tables ('Required (nullity ty))) where
100124 (+) = unsafeBinaryOp "+"
101125 (-) = unsafeBinaryOp "-"
102126 (*) = unsafeBinaryOp "*"
@@ -104,7 +128,7 @@ instance PGNum ty => Num (Expression params tables (nullity ty)) where
104128 signum = unsafeFunction "sign"
105129 fromInteger = UnsafeExpression . fromString . show
106130
107−instance IsString (Expression params tables (nullity 'PGText)) where
131+instance IsString (Expression params tables ('Required (nullity 'PGText))) where
108132 fromString str = UnsafeExpression $
109133 "E\'" <> fromString (escape =<< str) <> "\'"
110134 where
@@ -119,7 +143,7 @@ instance IsString (Expression params tables (nullity 'PGText)) where
119143 '\\' -> "\\\\"
120144 c -> [c]
121145
122−instance Boolean (Expression params tables ('NotNull 'PGBool)) where
146+instance Boolean (Expression params tables ('Required ('NotNull 'PGBool))) where
123147 true = UnsafeExpression "TRUE"
124148 false = UnsafeExpression "FALSE"
125149 notB = unsafeUnaryOp "NOT"
@@ -127,21 +151,10 @@ instance Boolean (Expression params tables ('NotNull 'PGBool)) where
127151 (||*) = unsafeBinaryOp "OR"
128152
129153type instance BooleanOf (Expression params tables ty) =
130− Expression params tables ('NotNull 'PGBool)
131−
132−coalesce
133− :: [Expression params tables ('Null x)]
134− -> Expression params tables ('NotNull x)
135− -> Expression params tables ('NotNull x)
136−coalesce nulls notNull = UnsafeExpression $ mconcat
137− [ "COALESCE("
138− , ByteString.intercalate ", " $ map renderExpression nulls
139− , ", ", renderExpression notNull
140− , ")"
141− ]
154+ Expression params tables ('Required ('NotNull 'PGBool))
142155
143156caseWhenThenElse
144− :: [(Expression params tables ('NotNull 'PGBool), Expression params tables ty)]
157+ :: [(Expression params tables ('Required ('NotNull 'PGBool)), Expression params tables ty)]
145158 -> Expression params tables ty
146159 -> Expression params tables ty
147160caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
@@ -160,115 +173,149 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
160173instance IfB (Expression params tables ty) where
161174 ifB if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
162175
163−instance EqB (Expression params tables ty) where
176+instance EqB (Expression params tables (optionality ('NotNull ty))) where
164177 (==*) = unsafeBinaryOp "="
165178 (/=*) = unsafeBinaryOp "<>"
166179
167−instance OrdB (Expression params tables ty) where
180+instance OrdB (Expression params tables (optionality ('NotNull ty))) where
168181 (>*) = unsafeBinaryOp ">"
169182 (>=*) = unsafeBinaryOp ">="
170183 (<*) = unsafeBinaryOp "<"
171184 (<=*) = unsafeBinaryOp "<="
172185
186+{-----------------------------------------
187+table expressions
188+-----------------------------------------}
189+
173190newtype TableExpression
174− (params :: [NullityType])
175− (schema :: [(Symbol,[(Symbol,NullityType)])])
176− (columns :: [(Symbol,NullityType)])
191+ (params :: [ColumnType])
192+ (schema :: [(Symbol,[(Symbol,ColumnType)])])
193+ (columns :: [(Symbol,ColumnType)])
177194 = UnsafeTableExpression { renderTableExpression :: ByteString }
195+ deriving (Show,Eq)
196+
197+class KnownSymbol table => HasTable table tables columns
198+ | table tables -> columns where
199+ getTable :: Proxy# table -> TableExpression params tables columns
200+ getTable table = UnsafeTableExpression $ fromString $ symbolVal' table
201+instance {-# OVERLAPPING #-} KnownSymbol table
202+ => HasTable table ((table ::: columns) ': tables) columns
203+instance {-# OVERLAPPABLE #-}
204+ (KnownSymbol table, HasTable table schema columns)
205+ => HasTable table (table' ': schema) columns
206+
207+instance HasTable table schema columns
208+ => IsLabel table (TableExpression params schema columns) where
209+ fromLabel = getTable
210+
211+{-----------------------------------------
212+statements
213+-----------------------------------------}
214+
215+newtype Statement
216+ (params :: [ColumnType])
217+ (columns :: [(Symbol,ColumnType)])
218+ (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
219+ (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
220+ = UnsafeStatement { renderStatement :: ByteString }
221+ deriving (Show,Eq)
222+
223+instance Category (Statement '[] '[]) where
224+ id = UnsafeStatement ";"
225+ statement2 . statement1 = UnsafeStatement $
226+ renderStatement statement1 <> " " <> renderStatement statement2
227+
228+newtype PreparedStatement
229+ (params :: [ColumnType])
230+ (columns :: [(Symbol,ColumnType)])
231+ (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
232+ (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
233+ = UnsafePreparedStatement { renderPreparedStatement :: ByteString }
234+ deriving (Show,Eq)
178235
179−data JoinExpression params schema tables where
236+{-----------------------------------------
237+SELECT statements
238+-----------------------------------------}
239+
240+data Join params schema tables where
180241 Table
181242 :: Aliased (TableExpression params schema) table
182− -> JoinExpression params schema '[table]
243+ -> Join params schema '[table]
183244 Subselect
184245 :: Aliased (Selection params schema) table
185− -> JoinExpression params schema '[table]
246+ -> Join params schema '[table]
186247 Cross
187248 :: Aliased (TableExpression params schema) table
188− -> JoinExpression params schema tables
189− -> JoinExpression params schema (table ': tables)
249+ -> Join params schema tables
250+ -> Join params schema (table ': tables)
190251 Inner
191252 :: Aliased (TableExpression params schema) table
192− -> Expression params (table ': tables) ('NotNull 'PGBool)
193− -> JoinExpression params schema tables
194− -> JoinExpression params schema (table ': tables)
253+ -> Expression params (table ': tables) ('Required ('NotNull 'PGBool))
254+ -> Join params schema tables
255+ -> Join params schema (table ': tables)
195256 LeftOuter
196257 :: Aliased (TableExpression params schema) right
197− -> Expression params '[left,right] ('NotNull 'PGBool)
198− -> JoinExpression params schema (tables)
199− -> JoinExpression params schema (NullifyTable right ': left ': tables)
258+ -> Expression params '[left,right] ('Required ('NotNull 'PGBool))
259+ -> Join params schema (tables)
260+ -> Join params schema (NullifyTable right ': left ': tables)
200261 RightOuter
201262 :: Aliased (TableExpression params schema) right
202− -> Expression params '[left,right] ('NotNull 'PGBool)
203− -> JoinExpression params schema (left : tables)
204− -> JoinExpression params schema (right ': NullifyTable left ': tables)
263+ -> Expression params '[left,right] ('Required ('NotNull 'PGBool))
264+ -> Join params schema (left : tables)
265+ -> Join params schema (right ': NullifyTable left ': tables)
205266 FullOuter
206267 :: Aliased (TableExpression params schema) right
207− -> Expression params '[left,right] ('NotNull 'PGBool)
208− -> JoinExpression params schema (left : tables)
209− -> JoinExpression params schema
268+ -> Expression params '[left,right] ('Required ('NotNull 'PGBool))
269+ -> Join params schema (left : tables)
270+ -> Join params schema
210271 (NullifyTable right ': NullifyTable left ': tables)
211272
212−renderJoinExpression :: JoinExpression params schema tables -> ByteString
213−renderJoinExpression = \case
273+renderJoin :: Join params schema tables -> ByteString
274+renderJoin = \case
214275 Table table -> renderAliased renderTableExpression table
215276 Subselect selection -> "SELECT " <> renderAliased renderSelection selection
216277 Cross table tables -> mconcat
217− [ renderJoinExpression tables
278+ [ renderJoin tables
218279 , " CROSS JOIN "
219280 , renderAliased renderTableExpression table
220281 ]
221282 Inner table on tables -> mconcat
222− [ renderJoinExpression tables
283+ [ renderJoin tables
223284 , " INNER JOIN "
224285 , renderAliased renderTableExpression table
225286 , " ON "
226287 , renderExpression on
227288 ]
228289 LeftOuter table on tables -> mconcat
229− [ renderJoinExpression tables
290+ [ renderJoin tables
230291 , " LEFT OUTER JOIN "
231292 , renderAliased renderTableExpression table
232293 , " ON "
233294 , renderExpression on
234295 ]
235296 RightOuter table on tables -> mconcat
236− [ renderJoinExpression tables
297+ [ renderJoin tables
237298 , " RIGHT OUTER JOIN "
238299 , renderAliased renderTableExpression table
239300 , " ON "
240301 , renderExpression on
241302 ]
242303 FullOuter table on tables -> mconcat
243− [ renderJoinExpression tables
304+ [ renderJoin tables
244305 , " FULL OUTER JOIN "
245306 , renderAliased renderTableExpression table
246307 , " ON "
247308 , renderExpression on
248309 ]
249310
250−class KnownSymbol table => HasTable table tables columns
251− | table tables -> columns where
252− getTable :: Proxy# table -> TableExpression params tables columns
253− getTable table = UnsafeTableExpression $ fromString $ symbolVal' table
254−instance {-# OVERLAPPING #-} KnownSymbol table
255− => HasTable table ((table ::: columns) ': tables) columns
256−instance {-# OVERLAPPABLE #-}
257− (KnownSymbol table, HasTable table schema columns)
258− => HasTable table (table' ': schema) columns
259−
260311instance HasTable table schema columns
261− => IsLabel table (TableExpression params schema columns) where
262− fromLabel = getTable
263−
264−instance HasTable table schema columns
265− => IsLabel table (JoinExpression params schema '[table ::: columns]) where
312+ => IsLabel table (Join params schema '[table ::: columns]) where
266313 fromLabel p = Table $ fromLabel p
267314
268315data Clauses params tables = Clauses
269− { whereClause :: Maybe (Expression params tables ('NotNull 'PGBool))
270− , limitClause :: Maybe (Expression params '[] ('NotNull 'PGInt8))
271− , offsetClause :: Maybe (Expression params '[] ('NotNull 'PGInt8))
316+ { whereClause :: Maybe (Expression params tables ('Required ('NotNull 'PGBool)))
317+ , limitClause :: Maybe (Expression params '[] ('Required ('NotNull 'PGInt8)))
318+ , offsetClause :: Maybe (Expression params '[] ('Required ('NotNull 'PGInt8)))
272319 }
273320
274321instance Monoid (Clauses params tables) where
@@ -291,124 +338,108 @@ instance Monoid (Clauses params tables) where
291338 (Just o1,Just o2) -> Just (o1 + o2)
292339 }
293340
294−data FromExpression
295− (params :: [NullityType])
296− (schema :: [(Symbol,[(Symbol,NullityType)])])
297− (tables :: [(Symbol,[(Symbol,NullityType)])])
298− = FromExpression
299− { joinExpression :: JoinExpression params schema tables
300− , clauses :: Clauses params tables
341+data From
342+ (params :: [ColumnType])
343+ (schema :: [(Symbol,[(Symbol,ColumnType)])])
344+ (tables :: [(Symbol,[(Symbol,ColumnType)])])
345+ = From
346+ { fromJoin :: Join params schema tables
347+ , fromClauses :: Clauses params tables
301348 }
302349
303350join
304− :: JoinExpression params schema tables
305− -> FromExpression params schema tables
306−join tref = FromExpression tref mempty
351+ :: Join params schema tables
352+ -> From params schema tables
353+join tables = From tables mempty
307354
308−renderFromExpression :: FromExpression params schema tables -> ByteString
309−renderFromExpression (FromExpression tref (Clauses wh lim off))= mconcat
310− [ renderJoinExpression tref
355+renderFrom :: From params schema tables -> ByteString
356+renderFrom (From tref (Clauses wh lim off))= mconcat
357+ [ renderJoin tref
311358 , maybe "" ((" WHERE " <>) . renderExpression) wh
312359 , maybe "" ((" LIMIT " <>) . renderExpression) lim
313360 , maybe "" ((" OFFSET " <>) . renderExpression) off
314361 ]
315362
316363instance (HasTable table schema columns, table ~ table')
317− => IsLabel table (FromExpression params schema '[table' ::: columns]) where
318− fromLabel p = FromExpression (fromLabel p) mempty
364+ => IsLabel table (From params schema '[table' ::: columns]) where
365+ fromLabel p = From (fromLabel p) mempty
319366
320367where_
321− :: Expression params tables ('NotNull 'PGBool)
322− -> FromExpression params schema tables
323− -> FromExpression params schema tables
324−where_ wh (FromExpression tabs clauses1) = FromExpression tabs
325− (clauses1 <> Clauses (Just wh) Nothing Nothing)
368+ :: Expression params tables ('Required ('NotNull 'PGBool))
369+ -> From params schema tables
370+ -> From params schema tables
371+where_ wh (From tabs fromClauses1) = From tabs
372+ (fromClauses1 <> Clauses (Just wh) Nothing Nothing)
326373
327374limit
328− :: Expression params '[] ('NotNull 'PGInt8)
329− -> FromExpression params schema tables
330− -> FromExpression params schema tables
331−limit lim (FromExpression tabs clauses1) = FromExpression tabs
332− (clauses1 <> Clauses Nothing (Just lim) Nothing)
375+ :: Expression params '[] ('Required ('NotNull 'PGInt8))
376+ -> From params schema tables
377+ -> From params schema tables
378+limit lim (From tabs fromClauses1) = From tabs
379+ (fromClauses1 <> Clauses Nothing (Just lim) Nothing)
333380
334381offset
335− :: Expression params '[] ('NotNull 'PGInt8)
336− -> FromExpression params schema tables
337− -> FromExpression params schema tables
338−offset off (FromExpression tabs clauses1) = FromExpression tabs
339− (clauses1 <> Clauses Nothing Nothing (Just off))
382+ :: Expression params '[] ('Required ('NotNull 'PGInt8))
383+ -> From params schema tables
384+ -> From params schema tables
385+offset off (From tabs fromClauses1) = From tabs
386+ (fromClauses1 <> Clauses Nothing Nothing (Just off))
340387
341388newtype Selection
342− (params :: [NullityType])
343− (schema :: [(Symbol,[(Symbol,NullityType)])])
344− (columns :: [(Symbol,NullityType)])
389+ (params :: [ColumnType])
390+ (schema :: [(Symbol,[(Symbol,ColumnType)])])
391+ (columns :: [(Symbol,ColumnType)])
345392 = UnsafeSelection { renderSelection :: ByteString }
393+ deriving (Show,Eq)
346394
347395starFrom
348396 :: tables ~ '[table ::: columns]
349− => FromExpression params schema tables
397+ => From params schema tables
350398 -> Selection params schema columns
351−starFrom tabs = UnsafeSelection $ "* FROM " <> renderFromExpression tabs
399+starFrom tabs = UnsafeSelection $ "* FROM " <> renderFrom tabs
352400
353401dotStarFrom
354402 :: HasTable table tables columns
355403 => Alias table
356− -> FromExpression params schema tables
404+ -> From params schema tables
357405 -> Selection params schema columns
358406Alias tab `dotStarFrom` tabs = UnsafeSelection $
359− fromString (symbolVal' tab) <> ".* FROM " <> renderFromExpression tabs
407+ fromString (symbolVal' tab) <> ".* FROM " <> renderFrom tabs
360408
361409from
362410 :: Rec (Aliased (Expression params tables)) columns
363− -> FromExpression params schema tables
411+ -> From params schema tables
364412 -> Selection params schema columns
365413list `from` tabs = UnsafeSelection $
366− renderList list <> " FROM " <> renderFromExpression tabs
414+ renderList list <> " FROM " <> renderFrom tabs
367415 where
368416 renderList
369417 = ByteString.intercalate ", "
370418 . recordToList
371419 . rmap (Const . renderAliased renderExpression)
372420
373−newtype Statement
374− (params :: [NullityType])
375− (schema0 :: [(Symbol,[(Symbol,NullityType)])])
376− (schema1 :: [(Symbol,[(Symbol,NullityType)])])
377− (columns :: [(Symbol,NullityType)])
378− = UnsafeStatement { renderStatement :: ByteString }
379−
380−(.>>.)
381− :: Statement params schema0 schema1 '[]
382− -> Statement params schema1 schema2 results
383− -> Statement params schema0 schema2 results
384−statement1 .>>. statement2 = UnsafeStatement $
385− renderStatement statement1 <> " " <> renderStatement statement2
386−
387−newtype PreparedStatement
388− (params :: [NullityType])
389− (schema0 :: [(Symbol,[(Symbol,NullityType)])])
390− (schema1 :: [(Symbol,[(Symbol,NullityType)])])
391− (columns :: [(Symbol,NullityType)])
392− = UnsafePreparedStatement { renderPreparedStatement :: ByteString }
393−
394421select
395422 :: Selection params schema columns
396− -> Statement params schema schema columns
423+ -> Statement params columns schema schema
397424select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
398425
399426subselect
400427 :: Aliased (Selection params schema) table
401− -> FromExpression params schema '[table]
402−subselect selection = FromExpression
403− { joinExpression = Subselect selection
404− , clauses = mempty
428+ -> From params schema '[table]
429+subselect selection = From
430+ { fromJoin = Subselect selection
431+ , fromClauses = mempty
405432 }
406433
434+{-----------------------------------------
435+INSERT statements
436+-----------------------------------------}
437+
407438insertInto
408439 :: HasTable table schema columns
409440 => Alias table
410441 -> Rec (Aliased (Expression params '[])) columns
411− -> Statement params schema schema '[]
442+ -> Statement params '[] schema schema
412443insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
413444 <> fromString (symbolVal' table)
414445 <> " (" <> ByteString.intercalate ", " aliases
@@ -423,22 +454,62 @@ insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
423454 (\ (expression `As` _) -> Const (renderExpression expression))
424455 expressions
425456
457+{-----------------------------------------
458+CREATE statements
459+-----------------------------------------}
460+
461+newtype TypeExpression (ty :: ColumnType)
462+ = UnsafeTypeExpression { renderTypeExpression :: ByteString }
463+ deriving (Show,Eq)
464+
465+int2 :: TypeExpression ('Required ('Null 'PGInt2))
466+int2 = UnsafeTypeExpression "int2"
467+int4 :: TypeExpression ('Required ('Null 'PGInt4))
468+int4 = UnsafeTypeExpression "int4"
469+int8 :: TypeExpression ('Required ('Null 'PGInt8))
470+int8 = UnsafeTypeExpression "int8"
471+bool :: TypeExpression ('Required ('Null 'PGBool))
472+bool = UnsafeTypeExpression "bool"
473+text :: TypeExpression ('Required ('Null 'PGText))
474+text = UnsafeTypeExpression "text"
475+notNull
476+ :: TypeExpression ('Required ('Null ty))
477+ -> TypeExpression ('Required ('NotNull ty))
478+notNull ty = UnsafeTypeExpression $ renderTypeExpression ty <> " NOT NULL"
479+default_
480+ :: Expression '[] '[] ('Required ty)
481+ -> TypeExpression ('Required ty)
482+ -> TypeExpression ('Optional ty)
483+default_ x ty = UnsafeTypeExpression $
484+ renderTypeExpression ty <> " DEFAULT " <> renderExpression x
485+serial :: TypeExpression ('Optional ('NotNull 'PGInt4))
486+serial = UnsafeTypeExpression "serial"
487+
426488createTable
427− :: (KnownSymbol table, KnownColumns columns)
428− => Alias table
429− -> Proxy# columns
430− -> Statement '[] schema ((table ::: columns) ': schema) '[]
489+ :: KnownSymbol table
490+ => Alias table
491+ -> Rec (Aliased TypeExpression) columns
492+ -> Statement '[] '[] schema ((table ::: columns) ': schema)
431493createTable (Alias table) columns = UnsafeStatement $ mconcat
432494 [ "CREATE TABLE "
433495 , fromString $ symbolVal' table
434496 , " ("
435− , renderColumns columns
497+ , ByteString.intercalate ", " . recordToList $
498+ rmap (Const . renderColumn) columns
436499 , ");"
437500 ]
501+ where
502+ renderColumn :: Aliased TypeExpression x -> ByteString
503+ renderColumn (ty `As` Alias column) =
504+ fromString (symbolVal' column) <> " " <> renderTypeExpression ty
505+
506+{-----------------------------------------
507+DROP statements
508+-----------------------------------------}
438509
439510class KnownSymbol table => DropTable table schema0 schema1
440511 | table schema0 -> schema1 where
441− dropTable :: Alias table -> Statement '[] schema0 schema1 '[]
512+ dropTable :: Alias table -> Statement '[] '[] schema0 schema1
442513 dropTable (Alias table) = UnsafeStatement $
443514 "DROP TABLE " <> fromString (symbolVal' table) <> ";"
444515instance {-# OVERLAPPING #-}
@@ -448,6 +519,10 @@ instance {-# OVERLAPPABLE #-}
448519 (KnownSymbol table, DropTable table schema0 schema1)
449520 => DropTable table (tabCols ': schema0) (tabCols ': schema1)
450521
522+{-----------------------------------------
523+UPDATE statements
524+-----------------------------------------}
525+
451526set :: g x -> (Maybe `Compose` g) x
452527set = Compose . Just
453528
@@ -458,8 +533,8 @@ update
458533 :: HasTable table schema columns
459534 => Alias table
460535 -> Rec (Aliased (Maybe `Compose` Expression params '[table ::: columns])) columns
461− -> Expression params '[table ::: columns] ('NotNull 'PGBool)
462− -> Statement params schema schema '[]
536+ -> Expression params '[table ::: columns] ('Required ('NotNull 'PGBool))
537+ -> Statement params '[] schema schema
463538update (Alias table) columns where' = UnsafeStatement $ mconcat
464539 [ "UPDATE "
465540 , fromString $ symbolVal' table