Skip to content

feat(sql-tursodatabase): add @effect/sql-tursodatabase driver for the Rust Turso engine#6522

Open
artile wants to merge 2 commits into
Effect-TS:mainfrom
artile:feat/sql-tursodatabase
Open

feat(sql-tursodatabase): add @effect/sql-tursodatabase driver for the Rust Turso engine#6522
artile wants to merge 2 commits into
Effect-TS:mainfrom
artile:feat/sql-tursodatabase

Conversation

@artile

@artile artile commented Jul 22, 2026

Copy link
Copy Markdown

Adds @effect/sql-tursodatabase, an @effect/sql implementation backed by the in-process Rust Turso engine (@tursodatabase/database), modeled on @effect/sql-libsql.

This is the migration of Effect-TS/effect-smol#2509 (closed because V4 development moved here). See that PR for the original discussion and review history.

Summary by CodeRabbit

  • New Features

    • Added @effect/sql-tursodatabase for SQL access via the in-process Turso engine.
    • Introduced a composable client layer with typed SQL error handling.
    • Added transaction support, including nested transactions and rollback behavior.
    • Added migration helpers for running and layering database migrations (streaming queries not included).
  • Tests

    • Added integration tests covering query execution, raw results, transactions, nested transactions, and rollbacks.
  • Documentation

    • Added package README and documentation generation configuration.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 22, 2026
@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0eacaa7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@effect/sql-tursodatabase Major
effect Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/vitest Major
@effect/ai-anthropic Major
@effect/ai-openai-compat Major
@effect/ai-openai Major
@effect/ai-openrouter Major
@effect/atom-react Major
@effect/atom-solid Major
@effect/atom-vue Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-pglite Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/openapi-generator Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a181b274-d2dd-461e-b6c4-6a1de615e5c8

📥 Commits

Reviewing files that changed from the base of the PR and between 4f70e21 and 0eacaa7.

📒 Files selected for processing (3)
  • packages/sql/tursodatabase/src/TursoClient.ts
  • packages/sql/tursodatabase/src/TursoMigrator.ts
  • packages/sql/tursodatabase/test/Client.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/sql/tursodatabase/test/Client.test.ts
  • packages/sql/tursodatabase/src/TursoMigrator.ts
  • packages/sql/tursodatabase/src/TursoClient.ts

📝 Walkthrough

Walkthrough

Adds @effect/sql-tursodatabase, an Effect SQL client for the in-process Turso engine, with typed errors, transactions, migration helpers, package exports, workspace configuration, and integration tests.

Changes

Turso Database SQL Driver

Layer / File(s) Summary
Turso client execution and transactions
packages/sql/tursodatabase/src/TursoClient.ts, packages/sql/tursodatabase/test/Client.test.ts
Defines managed and live connection configurations, SQL execution methods, typed SqlError handling, transaction support, Effect layers, and tests for raw queries, commits, rollbacks, nested transactions, and safe integers.
Migration helpers and public exports
packages/sql/tursodatabase/src/TursoMigrator.ts, packages/sql/tursodatabase/src/index.ts
Re-exports the shared migrator and adds run and layer helpers for executing Turso migrations.
Package publishing and workspace integration
packages/sql/tursodatabase/package.json, packages/sql/tursodatabase/{docgen.json,README.md,LICENSE,tsconfig.json,vitest.config.ts}, tsconfig.json, tsconfig.packages.json, .changeset/add-sql-tursodatabase.md
Adds package metadata, exports, dependencies, documentation and build configuration, TypeScript project wiring, licensing, and a minor-release changeset.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant TursoClient
  participant TursoDatabase
  Application->>TursoClient: Execute SQL effect
  TursoClient->>TursoDatabase: Prepare and execute statement
  TursoDatabase-->>TursoClient: Return rows or metadata
  TursoClient-->>Application: Return result or SqlError
Loading

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the @effect/sql-tursodatabase driver for the Rust Turso engine.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/sql/tursodatabase/src/TursoClient.ts (1)

136-146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer Effect.fnUntraced over a function that only returns Effect.gen.

make is a plain arrow function whose body is solely an Effect.gen call.

As per coding guidelines, "In Effect TypeScript code, prefer Effect.fnUntraced over functions that only return Effect.gen".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/sql/tursodatabase/src/TursoClient.ts` around lines 136 - 146, Update
the TursoClient make function to use Effect.fnUntraced rather than a plain arrow
function wrapping Effect.gen. Preserve the existing compiler setup, result-name
transformation logic, return type, and generator body unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/sql/tursodatabase/docgen.json`:
- Line 2: Update the paths in docgen.json: use
../../../node_modules/@effect/docgen/schema.json for $schema, and change the
effect source references from ../../../effect/src to ../../effect/src for both
index.js and the wildcard pattern.

In `@packages/sql/tursodatabase/src/TursoClient.ts`:
- Line 138: Update the TursoClient connection setup in make to use
Effect.tryPromise instead of Effect.promise, mapping connection failures to
SqlError so they follow the same error contract as prepare, run, and runValues.
Propagate the widened SqlError type through make, layerConfig, and layer while
preserving successful connection behavior.
- Around line 192-205: Update runValues to honor the Client.SafeIntegers
fiber-context setting just as runStatement does: check the setting and apply
statement.safeIntegers(true) before executing either reader or non-reader
statements. Preserve the existing raw/all and run execution paths and error
classification.

In `@packages/sql/tursodatabase/src/TursoMigrator.ts`:
- Around line 35-47: Update the public JSDoc for the exported layer function in
TursoMigrator.ts to use the package’s established `@category` layers convention,
matching the sibling layer and layerConfig APIs in TursoClient.ts; leave the
implementation unchanged.

---

Nitpick comments:
In `@packages/sql/tursodatabase/src/TursoClient.ts`:
- Around line 136-146: Update the TursoClient make function to use
Effect.fnUntraced rather than a plain arrow function wrapping Effect.gen.
Preserve the existing compiler setup, result-name transformation logic, return
type, and generator body unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0270ec6a-24aa-495e-a51f-d124552550c3

📥 Commits

Reviewing files that changed from the base of the PR and between b82248b and 4f70e21.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • .changeset/add-sql-tursodatabase.md
  • packages/sql/tursodatabase/LICENSE
  • packages/sql/tursodatabase/README.md
  • packages/sql/tursodatabase/docgen.json
  • packages/sql/tursodatabase/package.json
  • packages/sql/tursodatabase/src/TursoClient.ts
  • packages/sql/tursodatabase/src/TursoMigrator.ts
  • packages/sql/tursodatabase/src/index.ts
  • packages/sql/tursodatabase/test/Client.test.ts
  • packages/sql/tursodatabase/tsconfig.json
  • packages/sql/tursodatabase/vitest.config.ts
  • tsconfig.json
  • tsconfig.packages.json

Comment thread packages/sql/tursodatabase/docgen.json
Comment thread packages/sql/tursodatabase/src/TursoClient.ts Outdated
Comment thread packages/sql/tursodatabase/src/TursoClient.ts
Comment thread packages/sql/tursodatabase/src/TursoMigrator.ts
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 22, 2026
- runValues now honors SafeIntegers like runStatement (.values queries
  no longer silently lose integer precision); add a regression test
- classify connect() failures as SqlError (parity with sqlite-wasm's
  async in-process open), widening make/layer/layerConfig error channels
- @category layers for TursoMigrator.layer, per .patterns/jsdoc.md
@artile

artile commented Jul 22, 2026

Copy link
Copy Markdown
Author

Addressed the CodeRabbit review in 0eacaa779:

Applied (3):

  • runValues SafeIntegers — now mirrors runStatement (checks Client.SafeIntegers, calls statement.safeIntegers(true)); .values queries no longer lose integer precision. Added a regression test.
  • connect() error typing — wrapped in Effect.tryPromiseSqlError ("Failed to open database"), matching the in-process sqlite-wasm driver; make/layer/layerConfig error channels widened accordingly.
  • TursoMigrator.layer @categoryconstructorslayers.

Declined (2), with parity rationale on the threads:

  • docgen.json paths — current paths are identical to all 13 packages/sql/*/docgen.json files (incl. libsql/sqlite-node); the suggested roots would be the only divergence.
  • Effect.fnUntraced for make (nitpick) — every SQL driver (libsql, pg, mysql2, all sqlite-*, …) defines make as a plain arrow returning Effect.gen. make is a public constructor and keeping the established package-wide pattern is preferred over changing this one driver in isolation.

Local verification: tsc -b 0 errors, build OK, vitest 7/7 (6 original + the new SafeIntegers case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

1 participant