mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 05:24:22 +01:00
first commit (nonfunctional)
This commit is contained in:
@@ -1,24 +1,43 @@
|
||||
import { Storages } from '@/storages.ts';
|
||||
import { Command } from 'commander';
|
||||
|
||||
const store = await Storages.db();
|
||||
|
||||
console.warn('Exporting events...');
|
||||
|
||||
let count = 0;
|
||||
|
||||
for await (const msg of store.req([{}])) {
|
||||
if (msg[0] === 'EOSE') {
|
||||
break;
|
||||
}
|
||||
if (msg[0] === 'EVENT') {
|
||||
console.log(JSON.stringify(msg[2]));
|
||||
count++;
|
||||
}
|
||||
if (msg[0] === 'CLOSED') {
|
||||
console.error('Database closed unexpectedly');
|
||||
break;
|
||||
}
|
||||
interface ExportFilter {
|
||||
authors: string[];
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const exporter = new Command()
|
||||
.name('db:export')
|
||||
.description('Export the specified set of events from the Ditto database.')
|
||||
.version('0.1.0')
|
||||
.showHelpAfterError();
|
||||
|
||||
exporter
|
||||
// .option('')
|
||||
.action(async (args: ExportFilter) => {
|
||||
console.warn('Exporting events...');
|
||||
let count = 0;
|
||||
|
||||
for await (const msg of store.req([{}])) {
|
||||
if (msg[0] === 'EOSE') {
|
||||
break;
|
||||
}
|
||||
if (msg[0] === 'EVENT') {
|
||||
console.log(JSON.stringify(msg[2]));
|
||||
count++;
|
||||
}
|
||||
if (msg[0] === 'CLOSED') {
|
||||
console.error('Database closed unexpectedly');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
console.warn(`Exported ${count} events`);
|
||||
});
|
||||
|
||||
exporter.parse(Deno.args, { from: 'user' });
|
||||
}
|
||||
|
||||
console.warn(`Exported ${count} events`);
|
||||
Deno.exit();
|
||||
|
||||
Reference in New Issue
Block a user