ditto/scripts/db-populate-extensions.ts
2025-02-11 21:20:16 -06:00

27 lines
672 B
TypeScript

import { NostrEvent } from '@nostrify/nostrify';
import { Storages } from '@/storages.ts';
import { EventsDB } from '@/storages/EventsDB.ts';
const kysely = await Storages.kysely();
const query = kysely
.selectFrom('nostr_events')
.select(['id', 'kind', 'content', 'pubkey', 'tags', 'created_at', 'sig']);
for await (const row of query.stream()) {
const event: NostrEvent = { ...row, created_at: Number(row.created_at) };
const ext = EventsDB.indexExtensions(event);
try {
await kysely
.updateTable('nostr_events')
.set('search_ext', ext)
.where('id', '=', event.id)
.execute();
} catch {
// do nothing
}
}
Deno.exit();