mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
Introduce the Dialect trait as the boundary between the engine and the SQL dialect a frontend speaks. The engine hardcodes SQLite behavior in many places; the trait is the seam where a frontend substitutes its own surface, growing one hook per behavior that moves behind it, with SqliteDialect in core/dialect/sqlite.rs as the SQLite implementation. The first hook is schema loading: every path that parses a sqlite_schema table row back into a table definition now goes through Dialect::parse_table_sql instead of calling BTreeTable::from_sql directly. Rows written by internal engine paths (sequence backing tables, sqlite_sequence) are plain SQLite text with no frontend marker, so every dialect falls back to SQLite parsing for text it does not recognize as its own. The dialect is a mandatory, explicit argument on every database constructor — open_file, open, open_new, from_uri, and the async and bypass-registry variants — with no defaulting convenience wrappers: SQLite-compatible callers state Arc::new(SqliteDialect) at the call site, so the dialect a database runs under is always visible where it is opened. It is fixed at open time because the schema is parsed during open itself; a dialect installed later could never see rows stored by another frontend. The process-wide database registry rejects an open whose dialect name differs from the already-open instance, and engine-initiated secondary opens (ATTACH) propagate the parent database's dialect instead of assuming SQLite.
Turso dbhash
This is a rewrite of dbhash in Rust. It computes the SHA1 hash of SQLite database content, compatible with SQLite's dbhash utility.
The tool hashes database content, not the physical file format, making it deterministic across different database configurations. Identical data produces identical hashes regardless of page size, text encoding, freelist state, or vacuum history.
Usage
turso-dbhash database.db
# Filter tables by pattern
turso-dbhash --like "user%" database.db
# Hash only schema (no data)
turso-dbhash --schema-only database.db
# Hash only data (no schema)
turso-dbhash --without-schema database.db