@@ -85,11 +85,11 @@ backend = Backend
85 Right _ -> pure ()
85 Right _ -> pure ()
86 let onNotify :: forall a. VS (Id Task) Task a -> Transaction -> ReadDb (V (Id Task) Task a)
86 let onNotify :: forall a. VS (Id Task) Task a -> Transaction -> ReadDb (V (Id Task) Task a)
87 onNotify (VS requested) txn = do
87 onNotify (VS requested) txn = do
89 decoded <- ReadDb $ do
88 decoded <- ReadDb $ do
90 conn <- ask
89 conn <- ask
91 lift $ decodeTransaction conn txn
90 lift $ decodeTransaction conn txn
92 traceM $ show $ _db_tasks decoded
91 traceM $ show $ _db_tasks decoded
92+ traceM $ show $ _db_users decoded
93 tasks <- runSelectReturningList' $ select $ all_ $ _db_tasks db
93 tasks <- runSelectReturningList' $ select $ all_ $ _db_tasks db
94 pure $ V $ Map.intersectionWith (,) requested $ Map.fromList $ fmap (\x -> (TaskId $ _task_id x, First $ Just x)) tasks
94 pure $ V $ Map.intersectionWith (,) requested $ Map.fromList $ fmap (\x -> (TaskId $ _task_id x, First $ Just x)) tasks
95 onSubscribe :: forall a. VS (Id Task) Task a -> ReadDb (V (Id Task) Task a)
95 onSubscribe :: forall a. VS (Id Task) Task a -> ReadDb (V (Id Task) Task a)
@@ -103,6 +103,7 @@ backend = Backend
103 { _task_id = default_
103 { _task_id = default_
104 , _task_description = val_ a
104 , _task_description = val_ a
105 , _task_completed = val_ False
105 , _task_completed = val_ False
106+ , _task_assignee = val_ undefined
107 pure $ TaskId taskId
108 pure $ TaskId taskId
108 withApiHandler dbUri onRequest onNotify onSubscribe $ \handler -> do
109 withApiHandler dbUri onRequest onNotify onSubscribe $ \handler -> do
@@ -159,22 +160,42 @@ instance (GPatchDatabase (x p), GPatchDatabase (y p)) => GPatchDatabase ((x :*:
159 gDatabasePatchDecoder = gDatabasePatchDecoder :*: gDatabasePatchDecoder
160 gDatabasePatchDecoder = gDatabasePatchDecoder :*: gDatabasePatchDecoder
161instance PatchEntity be a => GPatchDatabase (S1 f (K1 Generic.R (EntityPatchDecoder be a)) p) where
162instance PatchEntity be a => GPatchDatabase (S1 f (K1 Generic.R (EntityPatchDecoder be a)) p) where
162− gDatabasePatchDecoder = M1 (K1 patchEntity)
163+ gDatabasePatchDecoder = M1 $ K1 patchEntity
164−class GPatchFields x where
165+type family FieldPatches be x where
165− gPatchFields :: x
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))))
167−instance GPatchFields (x p) => GPatchFields (D1 f x p) where
173+class GPatchFields be exposedRep where
168− gPatchFields = M1 gPatchFields
174+ gPatchFields :: FieldPatches be exposedRep ()
170−instance GPatchFields (x p) => GPatchFields (C1 f x p) where
176+instance GPatchFields be x => GPatchFields be (D1 f x) where
171− gPatchFields = M1 gPatchFields
177+ gPatchFields = M1 $ gPatchFields @be @x
173−instance (GPatchFields (x p), GPatchFields (y p)) => GPatchFields ((x :*: y) p) where
179+instance GPatchFields be x => GPatchFields be (C1 f x) where
174− gPatchFields = gPatchFields :*: gPatchFields
180+ gPatchFields = M1 $ gPatchFields @be @x
182+instance (GPatchFields be x, GPatchFields be y) => GPatchFields be (x :*: y) where
183+ gPatchFields = gPatchFields @be @x :*: gPatchFields @be @y
176−instance BackendFromField be a => GPatchFields (S1 f (K1 Generic.R (FieldDecoder be a)) p) where
185+instance BackendFromField be a => GPatchFields be (S1 f (K1 Generic.R (Exposed a))) where
177− gPatchFields = M1 (K1 FieldDecoder)
186+ gPatchFields = M1 $ K1 FieldDecoder
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))
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)))
179class PatchEntity be e where
200class PatchEntity be e where
180 patchEntity :: EntityPatchDecoder be e
201 patchEntity :: EntityPatchDecoder be e
@@ -186,12 +207,13 @@ to' :: Generic x => Rep x () -> x
186to' = Generic.to
207to' = Generic.to
188instance ( Generic (tbl (FieldDecoder be))
209instance ( Generic (tbl (FieldDecoder be))
210+ , GPatchFields be (Rep (tbl Exposed))
189− , GPatchFields (Rep (tbl (FieldDecoder be)) ())
211+ , FieldPatches be (Rep (tbl Exposed)) ~ Rep (tbl (FieldDecoder be))
190 , Table tbl
212 , Table tbl
191 , Ord (PrimaryKey tbl Identity)
213 , Ord (PrimaryKey tbl Identity)
192 , Eq (tbl Maybe)
214 , Eq (tbl Maybe)
193 ) => PatchEntity be (TableEntity tbl) where
215 ) => PatchEntity be (TableEntity tbl) where
194− patchEntity = EntityPatchDecoder_Table $ to' gPatchFields
216+ patchEntity = EntityPatchDecoder_Table $ to' $ gPatchFields @be @(Rep (tbl Exposed))
196defaultDatabasePatchDecoder
218defaultDatabasePatchDecoder
197 :: forall be db
219 :: forall be db
@@ -274,7 +296,6 @@ instance Beamable tbl => Patch (PartialUpdate tbl) where
274 type PatchTarget (PartialUpdate tbl) = tbl Identity
296 type PatchTarget (PartialUpdate tbl) = tbl Identity
275 apply (PartialUpdate new) old = zipBeamFieldsM (\(Columnar' newField) (Columnar' oldField) -> pure $ Columnar' $ fromMaybe oldField newField) new old
297 apply (PartialUpdate new) old = zipBeamFieldsM (\(Columnar' newField) (Columnar' oldField) -> pure $ Columnar' $ fromMaybe oldField newField) new old
277−--TODO: Inserts should always be complete; deletes should always have a key
278decodeChange
299decodeChange
279 :: forall tbl
300 :: forall tbl
280 . Table tbl
301 . Table tbl