@@ -240,3 +240,58 @@ instance
240240 let tableName = reflectSymbol (Proxy :: Proxy name)
241241 let conditions = whereClauseRL (Proxy :: Proxy whereRL) 1
242242 "SELECT * FROM " <> tableName <> " WHERE " <> intercalate " AND " conditions
243+
244+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
245+-- UPDATE SQL generation
246+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
247+
248+class ColumnCountRL :: RL.RowList Type -> Constraint
249+class ColumnCountRL rl where
250+ columnCountRL :: Proxy rl -> Int
251+
252+instance ColumnCountRL RL.Nil where
253+ columnCountRL _ = 0
254+
255+instance ColumnCountRL tail => ColumnCountRL (RL.Cons name typ tail) where
256+ columnCountRL _ = 1 + columnCountRL (Proxy :: Proxy tail)
257+
258+class UpdateSQLFor table setRow whereRow where
259+ updateSQLFor :: String
260+
261+instance
262+ ( IsSymbol name
263+ , RowToList setRow setRL
264+ , RowToList whereRow whereRL
265+ , WhereClauseRL setRL
266+ , WhereClauseRL whereRL
267+ , ColumnCountRL setRL
268+ ) =>
269+ UpdateSQLFor (Table name cols) setRow whereRow where
270+ updateSQLFor = do
271+ let tableName = reflectSymbol (Proxy :: Proxy name)
272+ let setClauses = whereClauseRL (Proxy :: Proxy setRL) 1
273+ let setCount = columnCountRL (Proxy :: Proxy setRL)
274+ let whereClauses = whereClauseRL (Proxy :: Proxy whereRL) (setCount + 1)
275+ "UPDATE " <> tableName
276+ <> " SET "
277+ <> intercalate ", " setClauses
278+ <> " WHERE "
279+ <> intercalate " AND " whereClauses
280+
281+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
282+-- DELETE SQL generation
283+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
284+
285+class DeleteSQLFor table whereRow where
286+ deleteSQLFor :: String
287+
288+instance
289+ ( IsSymbol name
290+ , RowToList whereRow whereRL
291+ , WhereClauseRL whereRL
292+ ) =>
293+ DeleteSQLFor (Table name cols) whereRow where
294+ deleteSQLFor = do
295+ let tableName = reflectSymbol (Proxy :: Proxy name)
296+ let conditions = whereClauseRL (Proxy :: Proxy whereRL) 1
297+ "DELETE FROM " <> tableName <> " WHERE " <> intercalate " AND " conditions