{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Data.Appendful.Persistent
(
clientMakeSyncRequestQuery,
clientMergeSyncResponseQuery,
clientSyncProcessor,
serverProcessSyncQuery,
serverProcessSyncWithCustomIdQuery,
serverSyncProcessor,
serverSyncProcessorWithCustomId,
setupUnsyncedClientQuery,
setupClientQuery,
clientGetStoreQuery,
serverGetStoreQuery,
setupServerQuery,
)
where
import Control.Monad
import Control.Monad.IO.Class
import Data.Appendful
import qualified Data.Map as M
import Data.Maybe
import Database.Persist
import Database.Persist.Sql
import Lens.Micro
clientMakeSyncRequestQuery ::
forall sid clientRecord a m.
( PersistEntity clientRecord,
PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
MonadIO m
) =>
(clientRecord -> a) ->
EntityField clientRecord (Maybe sid) ->
SqlPersistT m (SyncRequest (Key clientRecord) sid a)
clientMakeSyncRequestQuery :: forall sid clientRecord a (m :: * -> *).
(PersistEntity clientRecord, PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend, MonadIO m) =>
(clientRecord -> a)
-> EntityField clientRecord (Maybe sid)
-> SqlPersistT m (SyncRequest (Key clientRecord) sid a)
clientMakeSyncRequestQuery clientRecord -> a
func EntityField clientRecord (Maybe sid)
serverIdField = do
Map (Key clientRecord) a
syncRequestAdded <-
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (\(Entity Key clientRecord
cid clientRecord
ct) -> (Key clientRecord
cid, clientRecord -> a
func clientRecord
ct))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList
[EntityField clientRecord (Maybe sid)
serverIdField forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. forall a. Maybe a
Nothing]
[]
Maybe sid
syncRequestMaximumSynced <-
((\Entity clientRecord
e -> Entity clientRecord
e forall s a. s -> Getting a s a -> a
^. forall record field.
PersistEntity record =>
EntityField record field
-> forall (f :: * -> *).
Functor f =>
(field -> f field) -> Entity record -> f (Entity record)
fieldLens EntityField clientRecord (Maybe sid)
serverIdField) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall backend (m :: * -> *) record.
(PersistQueryRead backend, MonadIO m,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))
selectFirst
[EntityField clientRecord (Maybe sid)
serverIdField forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
!=. forall a. Maybe a
Nothing]
[forall record typ. EntityField record typ -> SelectOpt record
Desc EntityField clientRecord (Maybe sid)
serverIdField] ::
SqlPersistT m (Maybe sid)
forall (f :: * -> *) a. Applicative f => a -> f a
pure SyncRequest {Maybe sid
Map (Key clientRecord) a
syncRequestAdded :: Map (Key clientRecord) a
syncRequestMaximumSynced :: Maybe sid
syncRequestMaximumSynced :: Maybe sid
syncRequestAdded :: Map (Key clientRecord) a
..}
clientMergeSyncResponseQuery ::
( PersistEntity clientRecord,
PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord,
MonadIO m
) =>
(sid -> a -> clientRecord) ->
EntityField clientRecord (Maybe sid) ->
SyncResponse (Key clientRecord) sid a ->
SqlPersistT m ()
clientMergeSyncResponseQuery :: forall clientRecord sid (m :: * -> *) a.
(PersistEntity clientRecord, PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord, MonadIO m) =>
(sid -> a -> clientRecord)
-> EntityField clientRecord (Maybe sid)
-> SyncResponse (Key clientRecord) sid a
-> SqlPersistT m ()
clientMergeSyncResponseQuery sid -> a -> clientRecord
func EntityField clientRecord (Maybe sid)
serverIdField = forall (m :: * -> *) ci si a.
Monad m =>
ClientSyncProcessor ci si a m -> SyncResponse ci si a -> m ()
mergeSyncResponseCustom forall a b. (a -> b) -> a -> b
$ forall clientRecord sid (m :: * -> *) a.
(PersistEntity clientRecord, PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord, MonadIO m) =>
(sid -> a -> clientRecord)
-> EntityField clientRecord (Maybe sid)
-> ClientSyncProcessor (Key clientRecord) sid a (SqlPersistT m)
clientSyncProcessor sid -> a -> clientRecord
func EntityField clientRecord (Maybe sid)
serverIdField
clientSyncProcessor ::
( PersistEntity clientRecord,
PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord,
MonadIO m
) =>
(sid -> a -> clientRecord) ->
EntityField clientRecord (Maybe sid) ->
ClientSyncProcessor (Key clientRecord) sid a (SqlPersistT m)
clientSyncProcessor :: forall clientRecord sid (m :: * -> *) a.
(PersistEntity clientRecord, PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord, MonadIO m) =>
(sid -> a -> clientRecord)
-> EntityField clientRecord (Maybe sid)
-> ClientSyncProcessor (Key clientRecord) sid a (SqlPersistT m)
clientSyncProcessor sid -> a -> clientRecord
func EntityField clientRecord (Maybe sid)
serverIdField = ClientSyncProcessor {Map sid a -> ReaderT SqlBackend m ()
Map (Key clientRecord) sid -> ReaderT SqlBackend m ()
clientSyncProcessorSyncClientAdded :: Map (Key clientRecord) sid -> ReaderT SqlBackend m ()
clientSyncProcessorSyncServerAdded :: Map sid a -> ReaderT SqlBackend m ()
clientSyncProcessorSyncClientAdded :: Map (Key clientRecord) sid -> ReaderT SqlBackend m ()
clientSyncProcessorSyncServerAdded :: Map sid a -> ReaderT SqlBackend m ()
..}
where
clientSyncProcessorSyncServerAdded :: Map sid a -> ReaderT SqlBackend m ()
clientSyncProcessorSyncServerAdded Map sid a
m = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall k a. Map k a -> [(k, a)]
M.toList Map sid a
m) forall a b. (a -> b) -> a -> b
$ \(sid
si, a
st) ->
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m ()
insert_ forall a b. (a -> b) -> a -> b
$ sid -> a -> clientRecord
func sid
si a
st
clientSyncProcessorSyncClientAdded :: Map (Key clientRecord) sid -> ReaderT SqlBackend m ()
clientSyncProcessorSyncClientAdded Map (Key clientRecord) sid
m = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall k a. Map k a -> [(k, a)]
M.toList Map (Key clientRecord) sid
m) forall a b. (a -> b) -> a -> b
$ \(Key clientRecord
cid, sid
sid) ->
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> [Update record] -> ReaderT backend m ()
update Key clientRecord
cid [EntityField clientRecord (Maybe sid)
serverIdField forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Update v
=. forall a. a -> Maybe a
Just sid
sid]
serverProcessSyncQuery ::
( PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
SafeToInsert record,
MonadIO m
) =>
[Filter record] ->
(record -> a) ->
(a -> record) ->
SyncRequest ci (Key record) a ->
SqlPersistT m (SyncResponse ci (Key record) a)
serverProcessSyncQuery :: forall record (m :: * -> *) a ci.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
SafeToInsert record, MonadIO m) =>
[Filter record]
-> (record -> a)
-> (a -> record)
-> SyncRequest ci (Key record) a
-> SqlPersistT m (SyncResponse ci (Key record) a)
serverProcessSyncQuery [Filter record]
filters record -> a
funcTo a -> record
funcFrom = forall ci si a (m :: * -> *).
(Ord si, Monad m) =>
ServerSyncProcessor ci si a m
-> SyncRequest ci si a -> m (SyncResponse ci si a)
processServerSyncCustom forall a b. (a -> b) -> a -> b
$ forall record (m :: * -> *) a ci.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
SafeToInsert record, MonadIO m) =>
[Filter record]
-> (record -> a)
-> (a -> record)
-> ServerSyncProcessor ci (Key record) a (SqlPersistT m)
serverSyncProcessor [Filter record]
filters record -> a
funcTo a -> record
funcFrom
serverSyncProcessor ::
( PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
SafeToInsert record,
MonadIO m
) =>
[Filter record] ->
(record -> a) ->
(a -> record) ->
ServerSyncProcessor ci (Key record) a (SqlPersistT m)
serverSyncProcessor :: forall record (m :: * -> *) a ci.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
SafeToInsert record, MonadIO m) =>
[Filter record]
-> (record -> a)
-> (a -> record)
-> ServerSyncProcessor ci (Key record) a (SqlPersistT m)
serverSyncProcessor [Filter record]
filters record -> a
funcTo a -> record
funcFrom =
ServerSyncProcessor {ReaderT SqlBackend m (Map (Key record) a)
Map ci a -> ReaderT SqlBackend m (Map ci (Key record))
serverSyncProcessorRead :: ReaderT SqlBackend m (Map (Key record) a)
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci (Key record))
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci (Key record))
serverSyncProcessorRead :: ReaderT SqlBackend m (Map (Key record) a)
..}
where
serverSyncProcessorRead :: ReaderT SqlBackend m (Map (Key record) a)
serverSyncProcessorRead = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (\(Entity Key record
i record
record) -> (Key record
i, record -> a
funcTo record
record)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [Filter record]
filters []
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci (Key record))
serverSyncProcessorAddItems = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a b. (a -> b) -> a -> b
$ forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
insert forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> record
funcFrom
serverProcessSyncWithCustomIdQuery ::
( Ord sid,
PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
SafeToInsert record,
MonadIO m
) =>
SqlPersistT m sid ->
[Filter record] ->
(record -> (sid, a)) ->
(sid -> a -> record) ->
SyncRequest ci sid a ->
SqlPersistT m (SyncResponse ci sid a)
serverProcessSyncWithCustomIdQuery :: forall sid record (m :: * -> *) a ci.
(Ord sid, PersistEntity record,
PersistEntityBackend record ~ SqlBackend, SafeToInsert record,
MonadIO m) =>
SqlPersistT m sid
-> [Filter record]
-> (record -> (sid, a))
-> (sid -> a -> record)
-> SyncRequest ci sid a
-> SqlPersistT m (SyncResponse ci sid a)
serverProcessSyncWithCustomIdQuery SqlPersistT m sid
genId [Filter record]
filters record -> (sid, a)
funcTo sid -> a -> record
funcFrom = forall ci si a (m :: * -> *).
(Ord si, Monad m) =>
ServerSyncProcessor ci si a m
-> SyncRequest ci si a -> m (SyncResponse ci si a)
processServerSyncCustom forall a b. (a -> b) -> a -> b
$ forall sid record (m :: * -> *) a ci.
(Ord sid, PersistEntity record,
PersistEntityBackend record ~ SqlBackend, SafeToInsert record,
MonadIO m) =>
SqlPersistT m sid
-> [Filter record]
-> (record -> (sid, a))
-> (sid -> a -> record)
-> ServerSyncProcessor ci sid a (SqlPersistT m)
serverSyncProcessorWithCustomId SqlPersistT m sid
genId [Filter record]
filters record -> (sid, a)
funcTo sid -> a -> record
funcFrom
serverSyncProcessorWithCustomId ::
( Ord sid,
PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
SafeToInsert record,
MonadIO m
) =>
SqlPersistT m sid ->
[Filter record] ->
(record -> (sid, a)) ->
(sid -> a -> record) ->
ServerSyncProcessor ci sid a (SqlPersistT m)
serverSyncProcessorWithCustomId :: forall sid record (m :: * -> *) a ci.
(Ord sid, PersistEntity record,
PersistEntityBackend record ~ SqlBackend, SafeToInsert record,
MonadIO m) =>
SqlPersistT m sid
-> [Filter record]
-> (record -> (sid, a))
-> (sid -> a -> record)
-> ServerSyncProcessor ci sid a (SqlPersistT m)
serverSyncProcessorWithCustomId SqlPersistT m sid
genId [Filter record]
filters record -> (sid, a)
funcTo sid -> a -> record
funcFrom =
ServerSyncProcessor {ReaderT SqlBackend m (Map sid a)
Map ci a -> ReaderT SqlBackend m (Map ci sid)
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci sid)
serverSyncProcessorRead :: ReaderT SqlBackend m (Map sid a)
serverSyncProcessorRead :: ReaderT SqlBackend m (Map sid a)
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci sid)
..}
where
serverSyncProcessorRead :: ReaderT SqlBackend m (Map sid a)
serverSyncProcessorRead = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (record -> (sid, a)
funcTo forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall record. Entity record -> record
entityVal) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [Filter record]
filters []
serverSyncProcessorAddItems :: Map ci a -> ReaderT SqlBackend m (Map ci sid)
serverSyncProcessorAddItems = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a b. (a -> b) -> a -> b
$ \a
a -> do
sid
sid <- SqlPersistT m sid
genId
let record :: record
record = sid -> a -> record
funcFrom sid
sid a
a
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m ()
insert_ record
record
forall (f :: * -> *) a. Applicative f => a -> f a
pure sid
sid
setupUnsyncedClientQuery ::
( PersistEntity clientRecord,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord,
MonadIO m
) =>
(a -> clientRecord) ->
[a] ->
SqlPersistT m ()
setupUnsyncedClientQuery :: forall clientRecord (m :: * -> *) a.
(PersistEntity clientRecord,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord, MonadIO m) =>
(a -> clientRecord) -> [a] -> SqlPersistT m ()
setupUnsyncedClientQuery a -> clientRecord
func = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
insert forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> clientRecord
func)
setupClientQuery ::
( PersistEntity clientRecord,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord,
MonadIO m
) =>
(a -> clientRecord) ->
(sid -> a -> clientRecord) ->
ClientStore (Key clientRecord) sid a ->
SqlPersistT m ()
setupClientQuery :: forall clientRecord (m :: * -> *) a sid.
(PersistEntity clientRecord,
PersistEntityBackend clientRecord ~ SqlBackend,
SafeToInsert clientRecord, MonadIO m) =>
(a -> clientRecord)
-> (sid -> a -> clientRecord)
-> ClientStore (Key clientRecord) sid a
-> SqlPersistT m ()
setupClientQuery a -> clientRecord
funcU sid -> a -> clientRecord
funcS ClientStore {Map sid a
Map (Key clientRecord) a
clientStoreAdded :: forall ci si a. ClientStore ci si a -> Map ci a
clientStoreSynced :: forall ci si a. ClientStore ci si a -> Map si a
clientStoreSynced :: Map sid a
clientStoreAdded :: Map (Key clientRecord) a
..} = do
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall k a. Map k a -> [(k, a)]
M.toList Map (Key clientRecord) a
clientStoreAdded) forall a b. (a -> b) -> a -> b
$ \(Key clientRecord
cid, a
st) ->
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
insertKey
Key clientRecord
cid
(a -> clientRecord
funcU a
st)
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall k a. Map k a -> [(k, a)]
M.toList Map sid a
clientStoreSynced) forall a b. (a -> b) -> a -> b
$ \(sid
sid, a
st) ->
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m ()
insert_ (sid -> a -> clientRecord
funcS sid
sid a
st)
clientGetStoreQuery ::
( Ord sid,
PersistEntity clientRecord,
PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend,
MonadIO m
) =>
(clientRecord -> a) ->
EntityField clientRecord (Maybe sid) ->
SqlPersistT m (ClientStore (Key clientRecord) sid a)
clientGetStoreQuery :: forall sid clientRecord (m :: * -> *) a.
(Ord sid, PersistEntity clientRecord, PersistField sid,
PersistEntityBackend clientRecord ~ SqlBackend, MonadIO m) =>
(clientRecord -> a)
-> EntityField clientRecord (Maybe sid)
-> SqlPersistT m (ClientStore (Key clientRecord) sid a)
clientGetStoreQuery clientRecord -> a
func EntityField clientRecord (Maybe sid)
serverIdField = do
Map (Key clientRecord) a
clientStoreAdded <-
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (\(Entity Key clientRecord
cid clientRecord
ct) -> (Key clientRecord
cid, clientRecord -> a
func clientRecord
ct))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList
[ EntityField clientRecord (Maybe sid)
serverIdField forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
==. forall a. Maybe a
Nothing
]
[]
Map sid a
clientStoreSynced <-
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\e :: Entity clientRecord
e@(Entity Key clientRecord
_ clientRecord
ct) -> (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Entity clientRecord
e forall s a. s -> Getting a s a -> a
^. forall record field.
PersistEntity record =>
EntityField record field
-> forall (f :: * -> *).
Functor f =>
(field -> f field) -> Entity record -> f (Entity record)
fieldLens EntityField clientRecord (Maybe sid)
serverIdField) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure (clientRecord -> a
func clientRecord
ct))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList
[ EntityField clientRecord (Maybe sid)
serverIdField forall v typ.
PersistField typ =>
EntityField v typ -> typ -> Filter v
!=. forall a. Maybe a
Nothing
]
[]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ClientStore {Map sid a
Map (Key clientRecord) a
clientStoreSynced :: Map sid a
clientStoreAdded :: Map (Key clientRecord) a
clientStoreAdded :: Map (Key clientRecord) a
clientStoreSynced :: Map sid a
..}
serverGetStoreQuery ::
( PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
MonadIO m
) =>
(record -> a) ->
SqlPersistT m (ServerStore (Key record) a)
serverGetStoreQuery :: forall record (m :: * -> *) a.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
MonadIO m) =>
(record -> a) -> SqlPersistT m (ServerStore (Key record) a)
serverGetStoreQuery record -> a
func = forall si a. Map si a -> ServerStore si a
ServerStore forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (\(Entity Key record
stid record
st) -> (Key record
stid, record -> a
func record
st)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall record backend (m :: * -> *).
(MonadIO m, PersistQueryRead backend,
PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m [Entity record]
selectList [] []
setupServerQuery ::
( PersistEntity record,
PersistEntityBackend record ~ SqlBackend,
MonadIO m
) =>
(a -> record) ->
ServerStore (Key record) a ->
SqlPersistT m ()
setupServerQuery :: forall record (m :: * -> *) a.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
MonadIO m) =>
(a -> record) -> ServerStore (Key record) a -> SqlPersistT m ()
setupServerQuery a -> record
func ServerStore {Map (Key record) a
serverStoreItems :: forall si a. ServerStore si a -> Map si a
serverStoreItems :: Map (Key record) a
..} = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall k a. Map k a -> [(k, a)]
M.toList Map (Key record) a
serverStoreItems) forall a b. (a -> b) -> a -> b
$ \(Key record
i, a
e) -> forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
insertKey Key record
i forall a b. (a -> b) -> a -> b
$ a -> record
func a
e
#if !MIN_VERSION_persistent(2,14,0)
type SafeToInsert a = a ~ a
#endif