damus-io/nostrdb · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈
nostrdb
由 lmdb 支持的、速度异常快的 nostr 数据库。
nostrdb 以一种自定义的内存表示形式存储 nostr 事件,从而实现零拷贝以及对所有笔记字段的 O(1) 访问速度。这种方式与 flatbuffers 类似,但它是专为 nostr 事件而定制的。
随后,这些事件会在 lmdb 内部被映射到内存中,进而实现极快、零拷贝的访问与查询功能。
nostrdb 的整个设计几乎完全借鉴自 strfry1,那是速度最快的 nostr 中继服务。不同之处在于,nostrdb 被设计为可作为 C 库嵌入到任何需要完整 nostr 查询功能的应用程序中。
API
该 API 非常不稳定。nostrdb 处于密集开发阶段,因此目前请不要期望其任何接口都能保持稳定。
CLI
nostrdb 自带了一个便捷的 ndb 命令行工具,用于与 nostrdb 数据库进行交互。该工具相对较新,目前仅支持少量命令。
使用方法
usage: ndb [--skip-verification] [-d db_dir] <command>
commands
stat
search [--oldest-first] [--limit 42] <fulltext query>
query [-k 42] [-k 1337] [-l 42]
import <line-delimited json file>
settings
--skip-verification skip signature validation
-d <db_dir> set database directory
构建
$ make ndb
全文查询
nostrdb 支持全文查询。您可以如下方式导入一些测试事件:
$ make testdata/many-events.json
$ ndb --skip-verification import testdata/many-events.json
$ ndb search --limit 2 --oldest-first 'nosy ostrich'
[01] K<'ostrich' 7 1671217526 note_id:253309>
Q: What do you call a nosy ostrich?
A: A nosTrich!