You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is my current and proposed util function to work with both local and cloud KV databases:
constenv=awaitload();Deno.env.set("DENO_KV_ACCESS_TOKEN",env["DENO_KV_ACCESS_TOKEN"]);constmapKV=newMap();mapKV.set("Cloud",awaitDeno.openKv(env["LOCATION"]));mapKV.set("Local",awaitDeno.openKv());typeKvName="Cloud"|"Local"typeMapKV=Map<KvName,Deno.Kv>;typeTableName="Table 1"|"Table 2"|"Table 3";typeCountMap=Map<TableName,number>;exportasyncfunctionkvGet(key: Deno.KvKey,mapKV: MapKV){constresult=[]for(const[_kvName,kv]ofmapKV){result.push(awaitkv.get(key));}returnresult}exportasyncfunctionkvSet(key: Deno.KvKey,value: any,mapKV: MapKV){for(const[_kvName,kv]ofmapKV){awaitkv.set(key,value);}}exportasyncfunctionkvDelete(key: Deno.KvKey,mapKV: MapKV){for(const[_kvName,kv]ofmapKV){awaitkv.delete(key);}}exportasyncfunctionkvGetCount(tableName: TableName,kv: Deno.Kv){constcountMap=(awaitkv.get(["Counts of all tables"])).valueasCountMap;returncountMap.get(tableName)||0;}exportasyncfunctionkvSetValueAndCount(key: Deno.KvKey,value: any,tableName: TableName,mapKV: MapKV){for(const[_kvName,kv]ofmapKV){awaitkv.set(key,value);constcountMap=(awaitkv.get(["Counts of all tables"])).valueasCountMap;constcurrentCount=countMap.get(tableName)||0;countMap.set(tableName,currentCount+1);awaitkv.set(["Counts of all tables"],countMap);}}
Do you think it's suitable for this repo?
The text was updated successfully, but these errors were encountered:
ooker777
changed the title
An util function for setting values for both local and cloud KV, and increasing the total count number
Util functions for working with multiple databases
May 25, 2024
I'm unclear on the purpose of setting values in both local and cloud at the same time?
Other points:
Your kvGet() function doesn't return anything.
The kvSetValueAndCount isn't atomic. Let's say the count is 0 for all tables. You could have a situation where two requests both get the CountMap for the same TableName before updating it, both set-value-and-update-count, but now your table count is 1, but the table has two values on it.
Maybe it's because I'm a noob and haven't figured out a better way for this. It's for testing purpose. Sometimes my data has a significant change, and I want to test in local before updating to the cloud. By making the mapKv map, I can turn on and off which database I want to push by simply commenting or uncommenting these lines:
Thanks for your other feedback. I've fixed the kvGet(). As for the kvSetValueAndCount, you are talking about a table of a database has duplicated updates from both database setting, right? I'm not sure why that is the case.
Here is my current and proposed util function to work with both local and cloud KV databases:
Do you think it's suitable for this repo?
The text was updated successfully, but these errors were encountered: