Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQLite] Add Deno support for SQLite in drizzle-orm #3868

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

macoley
Copy link

@macoley macoley commented Dec 29, 2024

Add Deno SQLite Integration

This PR adds support for using Drizzle ORM with Deno's fastest native SQLite driver @db/sqlite.

Key Changes

  • Added new drizzle-orm/deno-sqlite integration
  • Implemented Deno-specific database driver and session handling
  • Added benchmarking example using Northwind database (similar to bun's example)
  • Added integration tests for Deno SQLite functionality

Implementation Details

The integration includes:

  • DenoSQLiteDatabase class extending BaseSQLiteDatabase for Deno-specific functionality
  • SQLiteDenoSession handling Deno SQLite statement preparation and execution
  • Support for transactions and prepared statements
  • Configuration options for database connection (readonly, memory, flags etc.)

Example Usage

import { Database } from '@db/sqlite';
import { drizzle } from 'drizzle-orm/deno-sqlite';

// Connect to SQLite database
const sqlite = new Database('database.db');
const db = drizzle(sqlite);

// Use Drizzle ORM as normal
const result = await db.select().from(users).all();

Testing

Integration tests

Added new test:deno command for testing package in Deno environment.
Screenshot 2024-12-29 at 20 00 54

New Deno example

Go to examplex/deno-sqlite and run deno run start (Deno environment needs to be installed).
Screenshot 2024-12-29 at 20 33 28

Breaking Changes

None. This is a new module that doesn't affect existing functionality.

- Updated .npmrc to include JSR registry.
- Enhanced drizzle-orm to support Deno with a new driver and session management for SQLite.
- Updated package.json to include @db/sqlite as a peer dependency.
- Added new files for Deno SQLite driver, session, and migrator functionalities.
- Updated README to include Deno SQLite connector example.
- Added new options for read-only mode, database creation, in-memory databases, BigInt support, aggressive optimizations, and extension loading.
- Updated existing option descriptions for clarity.
- Added exclusion for 'tests/deno/**/*' in vitest.config.ts files across drizzle-typebox, drizzle-valibot, and drizzle-zod.
- Updated package.json in drizzle-zod to exclude Deno tests from AVA test files.
- Modified dynamic import tests in integration-tests to account for 'drizzle-orm/deno-sqlite' in addition to existing conditions.
- Added deno.json and deno.lock for task management and dependency resolution.
- Developed a README.md to provide an overview and usage instructions for the Deno SQLite example.
- Implemented main.ts with various database queries and performance benchmarks using Drizzle ORM.
- Introduced meta.ts for managing sample data and search queries.
- Defined schema.ts for database table structures and types.

This commit establishes a foundational example for using Deno with SQLite in the drizzle-orm framework.
@macoley macoley marked this pull request as ready for review December 29, 2024 19:57
@macoley macoley changed the title Add Deno support for SQLite in drizzle-orm [SQLite] Add Deno support for SQLite in drizzle-orm Dec 29, 2024
@macoley
Copy link
Author

macoley commented Dec 30, 2024

Related discussion: #2440

@xkrsz
Copy link

xkrsz commented Dec 30, 2024

great job working on this, much appreciated

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.

2 participants