#sqlite #database #reader #file-read #pure #read-write

bin+lib sqlite-rs

纯 Rust 编写的 SQLite 读取器

13 个版本

0.3.7 2024年1月17日
0.3.6 2024年1月17日
0.2.1 2024年1月13日
0.1.8 2023年9月17日
0.1.5 2023年8月30日

#8 in #file-read

Download history 81/week @ 2024-07-23 31/week @ 2024-07-30

112 每月下载量

MIT 许可证

105KB
2.5K SLoC

sqlite-rs

纯 Rust 编写的无依赖的 SQLite 库(开发中)

通过 sqlite-rs CLI 入门

安装

cargo install sqlite-rs

从终端运行

内存中

sqlite-rs

文件(只读模式)

sqlite-rs --database-file=mydb.db?mode=ro

文件(读写模式)- 默认

sqlite-rs --database-file=mydb.db?mode=rw

或者

sqlite-rs --database-file=mydb.db

文件(读写和创建模式)

sqlite-rs --database-file=mydb.db?mode=rwc
sqlite-rs v0.3.3 - 1705457528
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite-rs> .dbinfo
database page size:  4096
write format:        1
read format:         1
reserved bytes:      0
file change counter: 0
database page count: 1
freelist page count: 0
schema cookie:       0
schema format:       4
default cache size:  0
autovacuum top root: 0
incremental vacuum:  0
text encoding:       1 (utf8)
user version:        0
application id:      0
software version:    303

从管道运行

echo '.dbinfo' | sqlite-rs
database page size:  4096
write format:        1
read format:         1
reserved bytes:      0
file change counter: 0
database page count: 1
freelist page count: 0
schema cookie:       0
schema format:       4
default cache size:  0
autovacuum top root: 0
incremental vacuum:  0
text encoding:       1 (utf8)
user version:        0
application id:      0
software version:    303

使用自定义日志级别 TRACE 运行

RUST_LOG="trace" sqlite-rs

或者

echo '.dbinfo' | RUST_LOG="trace" sqlite-rs
1705457633.7426755 TRACE sqlite_rs: Openning SQliteIo [:memory:]...
1705457633.7427387 TRACE sqlite_rs: SQliteIo started: [SqliteIo { mode: InMemory }].
1705457633.7427547 TRACE sqlite_rs: Connecting SqlitePager...
1705457633.7427745 TRACE sqlite_rs::pager: [0] Bytes read from [InMemory]
1705457633.7427909 TRACE sqlite_rs: SQliteIo started: [SqlitePager { io: SqliteIo { mode: InMemory }, page_size: L4096, reserved_bytes_per_page: ReservedBytesPerPage(0) }].
1705457633.7428088 TRACE sqlite_rs: Starting SqliteRuntime...
1705457633.7428281 TRACE sqlite_rs: SqliteRuntime started: [SqliteRuntime { pager: SqlitePager { io: SqliteIo { mode: InMemory }, page_size: L4096, reserved_bytes_per_page: ReservedBytesPerPage(0) }, header: SqliteHeader { magic_header_string: MagicHeaderString, page_size: L4096, file_format_version_numbers: FileFormatVersionNumbers { write_version: Legacy, read_version: Legacy }, reserved_bytes_per_page: ReservedBytesPerPage(0), payload_fractions: PayloadFractions { maximum: MaximumEmbeddedPayloadFraction(64), minimum: MinimumEmbeddedPayloadFraction(32), leaf: LeafPayloadFraction(32) }, file_change_counter: FileChangeCounter(0), db_filesize_in_pages: DatabaseFileSizeInPages(1), freelist_pages: FreeListPages { first: FreeListPagesFirstTrunkPage(0), total: FreeListPagesTotalPages(0) }, schema_cookie: SchemaCookie(0), schema_format: Format4, suggested_cache_size: SuggestedCacheSize(0), incremental_vacuum_settings: IncrementalVacuumSettings { largest_root_btree_page: LargestRootBtreePage(0), incremental_vacuum_mode: False }, database_text_encoding: Utf8, user_version: UserVersion(0), application_id: ApplicationId(0), reserved_for_expansion: ReservedForExpansion, version_valid_for: VersionValidFor(303), write_library_version: WriteLibraryVersion(303) }, btree: SqliteBtree(()) }].
database page size:  4096
write format:        1
read format:         1
reserved bytes:      0
file change counter: 0
database page count: 1
freelist page count: 0
schema cookie:       0
schema format:       4
default cache size:  0
autovacuum top root: 0
incremental vacuum:  0
text encoding:       1 (utf8)
user version:        0
application id:      0
software version:    303

运行 sqlite-rs 工具测试

git clone https://github.com/afsec/sqlite-rs
RUST_LOG="trace" cargo run -- --database-file=./data/flights-initial.db

运行测试

RUST_LOG="trace" cargo test -- --nocapture --test-threads=1

运行示例 sqlite_info

RUST_LOG="trace" cargo run --release --target=$(arch)-unknown-linux-musl --example sqlite_info

实时会话

路线图

  • SQLite 头部解析
  • 使用 RUST_LOG 环境变量进行日志记录
  • sqlite-rs CLI 工具
  • 分页器
  • 读取表
  • 读取表模式
  • 读取表行
  • 待定

无运行时依赖