Skip to content

feat(drizzle): update with postgres and mysql connectors#219

Merged
pi0 merged 6 commits into
mainfrom
feat/drizzle-postgres-connector
Mar 16, 2026
Merged

feat(drizzle): update with postgres and mysql connectors#219
pi0 merged 6 commits into
mainfrom
feat/drizzle-postgres-connector

Conversation

@pi0

@pi0 pi0 commented Mar 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Restructure drizzle integration into dialect-specific subdirectories (sqlite/, postgres/, mysql/) with backwards-compatible re-exports
  • Add db0/integrations/drizzle/postgres with full PgSession, PgTransaction, and PgPreparedQuery implementations
  • Add db0/integrations/drizzle/mysql with full MySqlSession, MySqlTransaction, and MySqlPreparedQuery implementations
  • Implement transactions and nested savepoints for all three dialects
  • Implement values() for SQLite, fillPlaceholders for proper placeholder handling
  • Remove unused _utils.ts (mapResultRow no longer needed since db0 returns object rows)

New structure

src/integrations/drizzle/
├── index.ts                  # Re-exports sqlite (backwards compatible)
├── sqlite/
│   ├── index.ts              # drizzle() for SQLite
│   └── _session.ts           # DB0SQLiteSession, DB0SQLiteTransaction, DB0SQLitePreparedQuery
├── postgres/
│   ├── index.ts              # drizzle() for PostgreSQL
│   └── _session.ts           # DB0PgSession, DB0PgTransaction, DB0PgPreparedQuery
└── mysql/
    ├── index.ts              # drizzle() for MySQL (supports mode: 'planetscale')
    └── _session.ts           # DB0MySqlSession, DB0MySqlTransaction, DB0MySqlPreparedQuery

Usage

// SQLite (unchanged, backwards compatible)
import { drizzle } from "db0/integrations/drizzle";

// PostgreSQL
import { drizzle } from "db0/integrations/drizzle/postgres";

// MySQL
import { drizzle } from "db0/integrations/drizzle/mysql";

Test plan

  • Existing SQLite drizzle tests pass (insert, select, schema, logger)
  • SQLite transaction tests (commit, rollback, nested savepoints)
  • PostgreSQL drizzle tests via pglite (insert, select, transactions, rollback, nested savepoints)
  • MySQL drizzle tests (behind MYSQL_URL env check)
  • Full test suite passes (57 tests, 0 failures)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Restructured drizzle ORM integration into database-specific modules for improved organization and maintainability.
  • New Features

    • Added MySQL integration for drizzle ORM.
    • Added PostgreSQL integration for drizzle ORM.
    • Enhanced SQLite integration with improved session management.
  • Tests

    • Added comprehensive integration tests for MySQL backend.
    • Added comprehensive integration tests for PostgreSQL backend.
    • Added comprehensive integration tests for SQLite backend with multiple connector support.

pi0 and others added 2 commits March 16, 2026 15:36
Restructure drizzle integration into dialect-specific subdirectories
(`sqlite/`, `postgres/`) with backwards-compatible re-exports from the
main entry point.

- Add `db0/integrations/drizzle/postgres` with full PgSession,
  PgTransaction, and PgPreparedQuery implementations
- Move SQLite session into `sqlite/` subdirectory
- Implement transactions and nested savepoints for both dialects
- Implement `values()` for SQLite (converts object rows to arrays)
- Use `fillPlaceholders` for proper placeholder handling
- Remove unused `_utils.ts` (mapResultRow no longer needed)
- Add pglite-based tests for the postgres connector

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 541e3262-7a61-4fbf-a937-7d84b0f8a29e

📥 Commits

Reviewing files that changed from the base of the PR and between c180379 and b799ea5.

📒 Files selected for processing (13)
  • src/integrations/drizzle/_session.ts
  • src/integrations/drizzle/_utils.ts
  • src/integrations/drizzle/index.ts
  • src/integrations/drizzle/mysql/_session.ts
  • src/integrations/drizzle/mysql/index.ts
  • src/integrations/drizzle/postgres/_session.ts
  • src/integrations/drizzle/postgres/index.ts
  • src/integrations/drizzle/sqlite/_session.ts
  • src/integrations/drizzle/sqlite/index.ts
  • test/integrations/drizzle.test.ts
  • test/integrations/drizzle/mysql.test.ts
  • test/integrations/drizzle/pg.test.ts
  • test/integrations/drizzle/sqlite.test.ts

📝 Walkthrough

Walkthrough

The PR refactors the Drizzle ORM integration from a single generic DB0 layer to database-specific implementations for SQLite, PostgreSQL, and MySQL. Each database now has dedicated session, transaction, and prepared query classes with updated test coverage and a restructured public API.

Changes

Cohort / File(s) Summary
SQLite Integration
src/integrations/drizzle/sqlite/_session.ts, src/integrations/drizzle/sqlite/index.ts
Implements DB0SQLiteSession, DB0SQLiteTransaction, and DB0SQLitePreparedQuery for SQLite backend with support for nested transactions via savepoints, placeholder substitution, and optional logging.
PostgreSQL Integration
src/integrations/drizzle/postgres/_session.ts, src/integrations/drizzle/postgres/index.ts
Introduces DB0PgSession, DB0PgTransaction, and DB0PgPreparedQuery for PostgreSQL backend with savepoint-based nested transaction support and count query helper.
MySQL Integration
src/integrations/drizzle/mysql/_session.ts, src/integrations/drizzle/mysql/index.ts
Adds DB0MySqlSession, DB0MySqlTransaction, and DB0MySqlPreparedQuery for MySQL backend with transaction initialization and savepoint-based nested transaction support.
API Entry Point Restructuring
src/integrations/drizzle/index.ts
Removed the generic drizzle function and types; now re-exports from sqlite implementation. Index becomes a pass-through to sqlite-specific exports with type aliases for backward compatibility.
Removed Generic Layer
src/integrations/drizzle/_session.ts, src/integrations/drizzle/_utils.ts
Deleted the monolithic DB0Session, DB0PreparedQuery classes and mapResultRow utility that previously provided a non-database-specific implementation.
SQLite Tests
test/integrations/drizzle/sqlite.test.ts
New test suite covering better-sqlite3, sqlite3, and libsql-node connectors with CRUD operations, transactions, savepoint nesting, and logger configuration.
PostgreSQL Tests
test/integrations/drizzle/pg.test.ts
New test suite for pglite and PostgreSQL connectors including insert, select, basic transactions, rollback, and nested transaction via savepoints.
MySQL Tests
test/integrations/drizzle/mysql.test.ts
New test suite for mysql2 connector covering insert, select, transaction commit, and transaction rollback scenarios.
Old Tests
test/integrations/drizzle.test.ts
Removed monolithic test file covering generic better-sqlite3, schema-aware, and PostgreSQL scenarios; replaced by database-specific test suites.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

The review requires verification of three parallel database-specific implementations following similar architectural patterns (session → transaction → prepared query), assessment of each database's unique control flow (particularly transaction and savepoint handling), validation of API surface changes and backward compatibility via re-exports, and confirmation that test coverage adequately replaces the removed monolithic tests. The heterogeneity of database-specific logic combined with architectural restructuring increases cognitive load.

Poem

🐰 Three databases stood in a line,
As monolithic turned to design,
SQLite, Postgres, MySQL so bright,
Each with their session, transaction, and plight,
Refactored with care, they hop through the night! 🌙

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/drizzle-postgres-connector
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

pi0 and others added 4 commits March 16, 2026 15:41
Add `db0/integrations/drizzle/mysql` with full MySqlSession,
MySqlTransaction, and MySqlPreparedQuery implementations.

- Supports transactions with isolation level, access mode, and
  consistent snapshot config
- Nested transactions via savepoints (InnoDB)
- Supports `mode` option for planetscale compatibility
- Add mysql2 test (behind MYSQL_URL env check)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pi0 pi0 changed the title feat(drizzle): add postgres connector and restructure by dialect feat(drizzle): update with postgres and mysql connectors Mar 16, 2026
@pi0 pi0 marked this pull request as ready for review March 16, 2026 19:07
@pi0 pi0 merged commit ca72c81 into main Mar 16, 2026
4 of 6 checks passed
@pi0 pi0 deleted the feat/drizzle-postgres-connector branch March 16, 2026 19:07
@arashsheyda arashsheyda mentioned this pull request Mar 16, 2026
6 tasks
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