Move DittoFilter to @/types.ts, refactor db/events query

This commit is contained in:
Alex Gleason 2023-08-16 12:54:17 -05:00
parent 4580b921c4
commit 8f45f3a7ad
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 14 additions and 11 deletions

View File

@ -1,7 +1,9 @@
import { db, type TagRow } from '@/db.ts'; import { db, type TagRow } from '@/db.ts';
import { type Filter, type Insertable } from '@/deps.ts'; import { type Insertable } from '@/deps.ts';
import { type SignedEvent } from '@/event.ts'; import { type SignedEvent } from '@/event.ts';
import type { DittoFilter } from '@/types.ts';
type TagCondition = ({ event, count }: { event: SignedEvent; count: number }) => boolean; type TagCondition = ({ event, count }: { event: SignedEvent; count: number }) => boolean;
/** Conditions for when to index certain tags. */ /** Conditions for when to index certain tags. */
@ -42,19 +44,12 @@ function insertEvent(event: SignedEvent): Promise<void> {
return results; return results;
}, []); }, []);
await Promise.all(tags.map((tag) => { await trx.insertInto('tags')
return trx.insertInto('tags') .values(tags)
.values(tag) .execute();
.execute();
}));
}); });
} }
/** Custom filter interface that extends Nostr filters with extra options for Ditto. */
interface DittoFilter<K extends number = number> extends Filter<K> {
local?: boolean;
}
/** Build the query for a filter. */ /** Build the query for a filter. */
function getFilterQuery(filter: DittoFilter) { function getFilterQuery(filter: DittoFilter) {
let query = db let query = db

8
src/types.ts Normal file
View File

@ -0,0 +1,8 @@
import { type Filter } from '@/deps.ts';
/** Custom filter interface that extends Nostr filters with extra options for Ditto. */
interface DittoFilter<K extends number = number> extends Filter<K> {
local?: boolean;
}
export { type DittoFilter };