aboutsummaryrefslogtreecommitdiffstats
path: root/lib/db.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-01-22 18:48:07 -0800
committerAdam Soltys <[email protected]>2026-01-22 18:48:07 -0800
commitd147e04d1b52f1359507a6f9d88e0227cf6bb250 (patch)
tree2eb562735a335831cec4737610f9638aaf50f32f /lib/db.ts
parent0edd59be4bbfc62f73b972e4992ec3c31d6baab1 (diff)
downloadcoinos-server-d147e04d1b52f1359507a6f9d88e0227cf6bb250.tar.gz
coinos-server-d147e04d1b52f1359507a6f9d88e0227cf6bb250.zip
read payments from archive
Diffstat (limited to 'lib/db.ts')
-rw-r--r--lib/db.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/db.ts b/lib/db.ts
index 56921adb..12e89757 100644
--- a/lib/db.ts
+++ b/lib/db.ts
@@ -152,6 +152,43 @@ export const sa = (k, v) => {
archive.set(k, JSON.stringify(v));
};
+// Get with fallback to archive
+export const gf = async (k) => {
+ let v = await db.get(k);
+ if (v === null) v = await archive.get(k);
+ try {
+ return JSON.parse(v);
+ } catch (e) {
+ return v;
+ }
+};
+
+// lRange with fallback to archive for missing items
+export const lRangeWithArchive = async (k, start, end) => {
+ const items = await db.lRange(k, start, end);
+ return items || [];
+};
+
+// Get payment/invoice with archive fallback - for individual lookups
+export const getWithArchive = async (prefix, id) => {
+ let v = await db.get(`${prefix}:${id}`);
+ if (v === null) v = await archive.get(`${prefix}:${id}`);
+ if (v === null) return null;
+ try {
+ const parsed = JSON.parse(v);
+ // If it's a reference to another key, follow it
+ if (typeof parsed === "string") {
+ let ref = await db.get(`${prefix}:${parsed}`);
+ if (ref === null) ref = await archive.get(`${prefix}:${parsed}`);
+ if (ref === null) return null;
+ return JSON.parse(ref);
+ }
+ return parsed;
+ } catch (e) {
+ return v;
+ }
+};
+
const retries = {};
export const t = async (k, f) => {
try {