@@ -85,11 +85,11 @@ backend = Backend
8585 Right _ -> pure ()
8686 let onNotify :: forall a. VS (Id Task) Task a -> Transaction -> ReadDb (V (Id Task) Task a)
8787 onNotify (VS requested) txn = do
88− traceM "Hello"
8988 decoded <- ReadDb $ do
9089 conn <- ask
9190 lift $ decodeTransaction conn txn
9291 traceM $ show $ _db_tasks decoded
92+ traceM $ show $ _db_users decoded
9393 tasks <- runSelectReturningList' $ select $ all_ $ _db_tasks db
9494 pure $ V $ Map.intersectionWith (,) requested $ Map.fromList $ fmap (\x -> (TaskId $ _task_id x, First $ Just x)) tasks
9595 onSubscribe :: forall a. VS (Id Task) Task a -> ReadDb (V (Id Task) Task a)
@@ -103,6 +103,7 @@ backend = Backend
103103 { _task_id = default_
104104 , _task_description = val_ a
105105 , _task_completed = val_ False
106+ , _task_assignee = val_ undefined
106107 }
107108 pure $ TaskId taskId
108109 withApiHandler dbUri onRequest onNotify onSubscribe $ \handler -> do
@@ -159,22 +160,42 @@ instance (GPatchDatabase (x p), GPatchDatabase (y p)) => GPatchDatabase ((x :*:
159160 gDatabasePatchDecoder = gDatabasePatchDecoder :*: gDatabasePatchDecoder
160161
161162instance PatchEntity be a => GPatchDatabase (S1 f (K1 Generic.R (EntityPatchDecoder be a)) p) where
162− gDatabasePatchDecoder = M1 (K1 patchEntity)
163+ gDatabasePatchDecoder = M1 $ K1 patchEntity
163164
164−class GPatchFields x where
165− gPatchFields :: x
165+type family FieldPatches be x where
166+ FieldPatches be (D1 f x) = D1 f (FieldPatches be x)
167+ FieldPatches be (C1 f x) = C1 f (FieldPatches be x)
168+ FieldPatches be (x :*: y) = FieldPatches be x :*: FieldPatches be y
169+ FieldPatches be (S1 f (K1 Generic.R (Exposed a))) = S1 f (K1 Generic.R (FieldDecoder be a))
170+ FieldPatches be (S1 f (K1 Generic.R (tbl Exposed))) = S1 f (K1 Generic.R (tbl (FieldDecoder be)))
171+ FieldPatches be (S1 f (K1 Generic.R (tbl (Nullable Exposed)))) = S1 f (K1 Generic.R (tbl (Nullable (FieldDecoder be))))
166172
167−instance GPatchFields (x p) => GPatchFields (D1 f x p) where
168− gPatchFields = M1 gPatchFields
173+class GPatchFields be exposedRep where
174+ gPatchFields :: FieldPatches be exposedRep ()
169175
170−instance GPatchFields (x p) => GPatchFields (C1 f x p) where
171− gPatchFields = M1 gPatchFields
176+instance GPatchFields be x => GPatchFields be (D1 f x) where
177+ gPatchFields = M1 $ gPatchFields @be @x
172178
173−instance (GPatchFields (x p), GPatchFields (y p)) => GPatchFields ((x :*: y) p) where
174− gPatchFields = gPatchFields :*: gPatchFields
179+instance GPatchFields be x => GPatchFields be (C1 f x) where
180+ gPatchFields = M1 $ gPatchFields @be @x
175181
176−instance BackendFromField be a => GPatchFields (S1 f (K1 Generic.R (FieldDecoder be a)) p) where
177− gPatchFields = M1 (K1 FieldDecoder)
182+instance (GPatchFields be x, GPatchFields be y) => GPatchFields be (x :*: y) where
183+ gPatchFields = gPatchFields @be @x :*: gPatchFields @be @y
184+
185+instance BackendFromField be a => GPatchFields be (S1 f (K1 Generic.R (Exposed a))) where
186+ gPatchFields = M1 $ K1 FieldDecoder
187+
188+instance ( GPatchFields be (Rep (tbl Exposed))
189+ , FieldPatches be (Rep (tbl Exposed)) ~ Rep (tbl (FieldDecoder be))
190+ , Generic (tbl (FieldDecoder be))
191+ ) => GPatchFields be (S1 f (K1 Generic.R (tbl Exposed))) where
192+ gPatchFields = M1 $ K1 $ to' $ gPatchFields @be @(Rep (tbl Exposed))
193+
194+instance ( GPatchFields be (Rep (tbl (Nullable Exposed)))
195+ , FieldPatches be (Rep (tbl (Nullable Exposed))) ~ Rep (tbl (Nullable (FieldDecoder be)))
196+ , Generic (tbl (Nullable (FieldDecoder be)))
197+ ) => GPatchFields be (S1 f (K1 Generic.R (tbl (Nullable Exposed)))) where
198+ gPatchFields = M1 $ K1 $ to' $ gPatchFields @be @(Rep (tbl (Nullable Exposed)))
178199
179200class PatchEntity be e where
180201 patchEntity :: EntityPatchDecoder be e
@@ -186,12 +207,13 @@ to' :: Generic x => Rep x () -> x
186207to' = Generic.to
187208
188209instance ( Generic (tbl (FieldDecoder be))
189− , GPatchFields (Rep (tbl (FieldDecoder be)) ())
210+ , GPatchFields be (Rep (tbl Exposed))
211+ , FieldPatches be (Rep (tbl Exposed)) ~ Rep (tbl (FieldDecoder be))
190212 , Table tbl
191213 , Ord (PrimaryKey tbl Identity)
192214 , Eq (tbl Maybe)
193215 ) => PatchEntity be (TableEntity tbl) where
194− patchEntity = EntityPatchDecoder_Table $ to' gPatchFields
216+ patchEntity = EntityPatchDecoder_Table $ to' $ gPatchFields @be @(Rep (tbl Exposed))
195217
196218defaultDatabasePatchDecoder
197219 :: forall be db
@@ -274,7 +296,6 @@ instance Beamable tbl => Patch (PartialUpdate tbl) where
274296 type PatchTarget (PartialUpdate tbl) = tbl Identity
275297 apply (PartialUpdate new) old = zipBeamFieldsM (\(Columnar' newField) (Columnar' oldField) -> pure $ Columnar' $ fromMaybe oldField newField) new old
276298
277−--TODO: Inserts should always be complete; deletes should always have a key
278299decodeChange
279300 :: forall tbl
280301 . Table tbl