diff --git a/flake.lock b/flake.lock index 80f1c52b..1709247d 100644 --- a/flake.lock +++ b/flake.lock @@ -370,11 +370,11 @@ "tinylog": "tinylog" }, "locked": { - "lastModified": 1733209116, - "narHash": "sha256-SBNA5q16n4L3H8wTs6i9aSjSKUamWdPWp2bOXBZobE4=", + "lastModified": 1733813522, + "narHash": "sha256-bK8/dUsyH/y5+Z8ssgjIW60Uo6nouGHtsOppbsgGSXM=", "owner": "nammayatri", "repo": "euler-hs", - "rev": "896a634222967245f6eb18ef8439aa324cd88ff4", + "rev": "9b89705853d12834e38e0c78501cf26db14b19e6", "type": "github" }, "original": { diff --git a/lib/mobility-core/src/Kernel/Beam/Functions.hs b/lib/mobility-core/src/Kernel/Beam/Functions.hs index 7ef6ef3b..322fdfb2 100644 --- a/lib/mobility-core/src/Kernel/Beam/Functions.hs +++ b/lib/mobility-core/src/Kernel/Beam/Functions.hs @@ -27,6 +27,7 @@ module Kernel.Beam.Functions deleteWithKV, deleteWithDb, -- not used findAllWithKVAndConditionalDB, + findAllWithKVAndConditionalDBWithOptions, findOneWithKVRedis, logQueryData, findAllFromKvRedis, @@ -318,6 +319,31 @@ findAllWithKVAndConditionalDB where' orderBy = do pure $ catMaybes res' Left err -> throwError $ InternalError $ show err +-- This function should be only used when you want data from kv only (order by will work in case of kv also) if present +-- and fall back to db if not present in kv then all three params orderby limit and offset will also work. + +findAllWithKVAndConditionalDBWithOptions :: + forall table m r a. + ( BeamTableFlow table m, + CacheFlow m r, + EsqDBFlow m r, + FromTType' (table Identity) a + ) => + Where Postgres table -> + Maybe (OrderBy table) -> + Maybe Int -> + Maybe Int -> + m [a] +findAllWithKVAndConditionalDBWithOptions where' orderBy mbLimit mbOffset = do + updatedMeshConfig <- setMeshConfig (modelTableName @table) (modelSchemaName @table) meshConfig + dbConf' <- getReadDBConfigInternal (modelTableName @table) + result <- KV.findAllWithKVAndConditionalDBWithOptionsInternal dbConf' updatedMeshConfig where' orderBy mbLimit mbOffset + case result of + Right res -> do + res' <- mapM fromTType' res + pure $ catMaybes res' + Left err -> throwError $ InternalError $ show err + findAllFromKvRedis :: forall table m r a. ( BeamTableFlow table m,