-
Notifications
You must be signed in to change notification settings - Fork 9
/
db_explore.js
42 lines (36 loc) · 995 Bytes
/
db_explore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env node
import createBee from './bee.js'
import * as SDK from 'hyper-sdk'
import goodbye from './goodbye.js'
import { DB } from 'hyperdeebee'
import { createInterface } from 'readline'
const int = createInterface(process.stdin, process.stdout)
const prefix = 'hyper-nostr-'
const sdk = await SDK.create({
storage: '.hyper-nostr-relay',
autoJoin: true
})
goodbye(_ => sdk.close())
const topic = prefix + process.argv[2]
const db = new DB(await createBee(sdk, topic))
let input
while (true) {
input = await question('Enter your query: ')
if (input === 'q') {
int.close()
process.exit(0)
}
try {
input = JSON.parse(input)
} catch {
console.log('Invalid query, try again (it has to follow JSON format)')
continue
}
for await (const event of db.collection('events').find(input)) console.log(event)
}
function question (prompt) {
let res
const promise = new Promise(resolve => (res = resolve))
int.question(prompt, res)
return promise
}