Skip to content

Implement remote libSQL DDL support and refactor DDL builders - #4

Open
jonaspm wants to merge 8 commits into
mainfrom
feat/alter
Open

Implement remote libSQL DDL support and refactor DDL builders#4
jonaspm wants to merge 8 commits into
mainfrom
feat/alter

Conversation

@jonaspm

@jonaspm jonaspm commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements remote DDL support (ALTER COLUMN, foreign key mutations) for Turso/sqld connections via the libSQL fork, rewrites the client to use the embedded libSQL fork of SQLite (replacing the rusqlite driver), and lands a round of contract fixes to match the host's RpcDriver expectations.

Changes

  • libSQL fork everywhere — local connections now use the embedded libsql crate (core feature, bundled) instead of rusqlite, so fork extensions (ALTER COLUMN, FK add/drop) work on local files and remote servers alike. No async runtime: bridged with futures::executor::block_on.
  • Remote DDLget_alter_column_sql, get_create_foreign_key_sql, drop_foreign_key now work against remote backends, gated by a new is_remote check on Client (src/client.rs). The FK builder emits the libSQL ALTER COLUMN col TO col <type> REFERENCES ... form, introspecting the column type via PRAGMA table_info (host now passes connection params through for this method).
  • DDL builder refactor — SQL builders in src/handlers/ddl.rs rewritten as pure functions that don't require a connection; DDL responses consistently return arrays of SQL strings.
  • Metadata contract fixes — column keys renamed is_primary_keyis_pk, column_defaultdefault_value; unused comment field removed. Test added to pin the contract keys.
  • connection_uri support — new ConnectionParams.connection_uri field; resolve_backend now treats the raw URI as authoritative over decomposed host/password fields, preserving auth tokens. .tabularium advertises connection_uri/connection_uri_schemes. Tests cover precedence, backend resolution, and token preservation.
  • get_triggers RPC method — new handler, enabled with the other metadata changes.
  • CRUD fix — insert returns affected rows count instead of null.
  • .tabularium capabilitiesalter_column: true, create_foreign_keys: true kept in sync with actual behavior.
  • Docs — README updated for the remote/local behavior split and host contracts.

Testing

  • cargo test (unit tests incl. new FK builder, local unsupported error, contract keys, connection URI resolution)
  • cargo clippy --all-targets -- -D warnings
  • cargo fmt --all

jonaspm added 6 commits August 7, 2026 21:41
Enable `ALTER COLUMN` and foreign key mutations for remote Turso/sqld
connections using the libSQL fork. Local SQLite connections continue to
return a clear unsupported error.

- Add `is_remote` check to `Client` to gate libSQL-specific features
- Implement `get_alter_column_sql`, `get_create_foreign_key_sql`, and
  `drop_foreign_key` for remote backends
- Update `.tabularium` capabilities for `alter_column` and
  `create_foreign_keys`
- Update README and metadata handlers to align with host contracts
- Ensure DDL responses return arrays of SQL strings
Refactor `src/handlers/ddl.rs` to implement SQL builders as pure
functions
that do not require database connections.

Disable `create_foreign_keys` in `.tabularium` and return an unsupported
error in `get_create_foreign_key_sql`, as the host protocol does not
provide the column type necessary for libSQL's `ALTER COLUMN` rewrite.

Update README and internal documentation to clarify the distinction
between remote libSQL extensions and vanilla SQLite limitations.
Rename `is_primary_key` to `is_pk` and `column_default` to
`default_value`, and remove the unused `comment` field. Add a test
to verify the contract keys.
`create_foreign_keys` capability in `.tabularium`. Update the
`get_create_foreign_key_sql` handler to receive and use connection
params, and emit the libSQL `ALTER COLUMN` form. Add tests for the new
foreign key builder and local unsupported error.
`resolve_backend` logic to use the raw URI when available, allowing it
to be authoritative over decomposed host and password fields. Add tests
covering `connection_uri` precedence, URL vs. local backend resolution,
and token preservation. Update `.tabularium` capabilities to support
`connection_uri` and `connection_uri_schemes`.
@jonaspm
jonaspm marked this pull request as draft August 10, 2026 23:17
code to use the embedded libSQL fork instead of the rusqlite driver.

Changes:
- `Cargo.toml`: replace `rusqlite` with `libsql = { version = "0.9",
  default-features = false, features = ["core"] }`, add `futures`,
  update description to mention the fork, `core` feature, async/sync
  bridge
- `src/client.rs`: switch to `libsql::Connection` and `libsql::Value`,
  adapt all local connections, `open_local`, `local_query`,
  `json_to_libsql`, `libsql_value_to_json`, and rename `is_remote`
  comment
- `src/error.rs`: change `From<rusqlite::Error>` to
  `From<libsql::Error>`
- `src/handlers/ddl.rs`: remove `require_remote` (local works through
  fork), update docs for `get_create_foreign_key_sql`,
  `drop_foreign_key`, and `drop_index`, update
  `get_create_foreign_key_sql` test to use temp file
- `src/handlers/metadata.rs`: adjust formatting of a wrapped `connect`
  call
- `src/rpc.rs`: rename test to describe local fork working through
  `get_create_foreign_key_sql`
- `src/utils/values.rs`: update comment to say libsql (local) instead of
  rusqlite (local)
@jonaspm

jonaspm commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author
image @debba one thing I haven't included here is a fix to the justfile for the windows dev-install script but also for the other OS installation locations.

@jonaspm
jonaspm requested a review from debba August 11, 2026 19:06
@jonaspm
jonaspm marked this pull request as ready for review August 11, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant