@@ -240,3 +240,58 @@ instance
240 let tableName = reflectSymbol (Proxy :: Proxy name)
240 let tableName = reflectSymbol (Proxy :: Proxy name)
241 let conditions = whereClauseRL (Proxy :: Proxy whereRL) 1
241 let conditions = whereClauseRL (Proxy :: Proxy whereRL) 1
242 "SELECT * FROM " <> tableName <> " WHERE " <> intercalate " AND " conditions
242 "SELECT * FROM " <> tableName <> " WHERE " <> intercalate " AND " conditions
244+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
245+-- UPDATE SQL generation
246+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
248+class ColumnCountRL :: RL.RowList Type -> Constraint
249+class ColumnCountRL rl where
250+ columnCountRL :: Proxy rl -> Int
252+instance ColumnCountRL RL.Nil where
255+instance ColumnCountRL tail => ColumnCountRL (RL.Cons name typ tail) where
256+ columnCountRL _ = 1 + columnCountRL (Proxy :: Proxy tail)
258+class UpdateSQLFor table setRow whereRow where
259+ updateSQLFor :: String
263+ , RowToList setRow setRL
264+ , RowToList whereRow whereRL
265+ , WhereClauseRL setRL
266+ , WhereClauseRL whereRL
267+ , ColumnCountRL setRL
269+ UpdateSQLFor (Table name cols) setRow whereRow where
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
277+ <> intercalate ", " setClauses
279+ <> intercalate " AND " whereClauses
281+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
282+-- DELETE SQL generation
283+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
285+class DeleteSQLFor table whereRow where
286+ deleteSQLFor :: String
290+ , RowToList whereRow whereRL
291+ , WhereClauseRL whereRL
293+ DeleteSQLFor (Table name cols) whereRow where
295+ let tableName = reflectSymbol (Proxy :: Proxy name)
296+ let conditions = whereClauseRL (Proxy :: Proxy whereRL) 1
297+ "DELETE FROM " <> tableName <> " WHERE " <> intercalate " AND " conditions