Pure MoonBit read-only SQLite file format parser and inspector
git clone https://github.com/prowk/MoonSQLiteFile.git
cd MoonSQLiteFile
moon build --target js cmd/inspect
node tools/inspect.cjs fixtures/core.sqlite header
node tools/inspect.cjs fixtures/core.sqlite schema
node tools/inspect.cjs fixtures/core.sqlite page 3
node tools/inspect.cjs fixtures/core.sqlite rows samples
node tools/inspect.cjs fixtures/core.sqlite rows branches 5
node tools/inspect.cjs fixtures/core.sqlite freelist
node tools/inspect.cjs fixtures/btree.sqlite records keyed 5
node tools/inspect.cjs fixtures/btree.sqlite index mixed_index 5
node tools/inspect.cjs fixtures/btree.sqlite scan 49 10import {
"prowk/moonsqlitefile" @sqlite,
}fn inspect(data : Bytes) -> Array[@sqlite.Row] raise @sqlite.SqliteError {
let db = @sqlite.open_database(data)
db.table_rows("samples", limit=10)
}moon run --target js examples/basicmoon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
moon fmt --check
python tools/generate_fixtures.py --check
python tools/verify_oracle.py
python tools/generate_btree_fixtures.py --check
python tools/verify_btree_oracle.py
python tools/verify_consumer.pypub(open) trait PageSource {
fn byte_length(Self) -> Int
fn read_range(Self, Int, Int) -> Bytes raise SqliteError
}pub(all) suberror SqliteError {
Invalid(String)
Unsupported(String)
LimitExceeded(String)
} derive(Debug)pub struct BytesSource {
data : Bytes
}impl PageSource for BytesSourcefn BytesSource::read_range(self : BytesSource, offset : Int, count : Int) -> Bytes raise SqliteErrorfn Database::index_records(self : Database, name : String, limit? : Int) -> Array[BTreeRecord] raise SqliteErrorfn Database::read_btree(self : Database, root : Int, limit? : Int, max_total_payload_bytes? : UInt64) -> Array[BTreeRecord] raise SqliteErrorfn Database::read_index(self : Database, root : Int, limit? : Int) -> Array[BTreeRecord] raise SqliteErrorfn Database::scan_btree(self : Database, root : Int, visit : (BTreeRecord) -> Bool raise SqliteError, limit? : Int, max_total_payload_bytes? : UInt64) -> ScanSummary raise SqliteErrorfn Database::table_records(self : Database, name : String, limit? : Int) -> Array[BTreeRecord] raise SqliteErrorpub(all) struct Header {
page_size : Int
usable_size : Int
write_version : Int
read_version : Int
change_counter : UInt
declared_pages : UInt
freelist_trunk : UInt
freelist_pages : UInt
schema_cookie : UInt
schema_format : Int
text_encoding : Int
user_version : UInt
application_id : UInt
version_valid_for : UInt
sqlite_version : UInt
} derive(Eq, Debug)pub(all) struct Limits {
max_rows : Int
max_payload_bytes : Int
max_pages : Int
max_depth : Int
} derive(Debug)pub(all) struct ScanSummary {
records_read : Int
pages_read : Int
payload_bytes : UInt64
completion : ScanCompletion
} derive(Debug)pub(all) struct SchemaEntry {
object_type : String
name : String
table_name : String
root_page : Int
sql : String?
} derive(Debug)Install
Download zipPure MoonBit read-only SQLite file format parser and inspector