From 9da4fb2bba48d2bc1b80e372a40a4f6edf310ce4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 12 Aug 2023 15:45:58 -0500 Subject: [PATCH] db/events: add comments --- src/db/events.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/db/events.ts b/src/db/events.ts index 4d14f83..4bdea6c 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -15,6 +15,7 @@ const tagConditions: Record = { 't': ({ count }) => count < 5, }; +/** Insert an event (and its tags) into the database. */ function insertEvent(event: SignedEvent): Promise { return db.transaction().execute(async (trx) => { await trx.insertInto('events') @@ -50,10 +51,12 @@ function insertEvent(event: SignedEvent): Promise { }); } +/** Custom filter interface that extends Nostr filters with extra options for Ditto. */ interface DittoFilter extends Filter { local?: boolean; } +/** Build the query for a filter. */ function getFilterQuery(filter: DittoFilter) { let query = db .selectFrom('events') @@ -107,6 +110,7 @@ function getFilterQuery(filter: DittoFilter) { return query; } +/** Get events for filters from the database. */ async function getFilters(filters: [DittoFilter]): Promise[]>; async function getFilters(filters: DittoFilter[]): Promise; async function getFilters(filters: DittoFilter[]) { @@ -121,6 +125,7 @@ async function getFilters(filters: DittoFilter[]) { )); } +/** Get events for a filter from the database. */ function getFilter(filter: DittoFilter): Promise[]> { return getFilters([filter]); }