Add db:import task

This commit is contained in:
Alex Gleason
2024-08-02 16:54:35 -05:00
parent 3bec54ee76
commit ba3f816955
4 changed files with 44 additions and 3 deletions

24
scripts/db-import.ts Normal file
View File

@@ -0,0 +1,24 @@
import { NostrEvent } from '@nostrify/nostrify';
import { JsonParseStream } from '@std/json/json-parse-stream';
import { TextLineStream } from '@std/streams/text-line-stream';
import { Storages } from '@/storages.ts';
const store = await Storages.db();
console.warn('Importing events...');
let count = 0;
const readable = Deno.stdin.readable
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream())
.pipeThrough(new JsonParseStream());
for await (const event of readable) {
await store.event(event as unknown as NostrEvent);
count++;
}
console.warn(`Imported ${count} events`);
Deno.exit();