From d182dfeb7fd7ee2ba62463b59c8edca234d95d51 Mon Sep 17 00:00:00 2001 From: onmax Date: Sat, 7 Feb 2026 12:52:50 +0100 Subject: [PATCH 1/4] docs: add db0 connector --- src/content/docs/_meta.json | 1 + src/content/docs/connect-db0.mdx | 100 ++++++++++++++++++++++++++ src/content/docs/connect-overview.mdx | 5 +- 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/content/docs/connect-db0.mdx diff --git a/src/content/docs/_meta.json b/src/content/docs/_meta.json index 47ccf72d..5e96103a 100644 --- a/src/content/docs/_meta.json +++ b/src/content/docs/_meta.json @@ -51,6 +51,7 @@ ["connect-aws-data-api-pg", "AWS Data API Postgres"], ["connect-aws-data-api-mysql", "AWS Data API MySQL"], "---", + ["connect-db0", "db0"], ["connect-drizzle-proxy", "Drizzle Proxy"], "Manage schema", diff --git a/src/content/docs/connect-db0.mdx b/src/content/docs/connect-db0.mdx new file mode 100644 index 00000000..08fd9900 --- /dev/null +++ b/src/content/docs/connect-db0.mdx @@ -0,0 +1,100 @@ +import Npm from "@mdx/Npm.astro"; +import Callout from '@mdx/Callout.astro'; +import Prerequisites from "@mdx/Prerequisites.astro"; +import CodeTabs from "@mdx/CodeTabs.astro"; +import WhatsNextPostgres from "@mdx/WhatsNextPostgres.astro"; + +# Drizzle \<\> db0 + + +- Database [connection basics](/docs/connect-overview) with Drizzle +- db0 (recommended `>= 0.3.4`) - [website](https://db0.unjs.io) & [GitHub](https://github.com/unjs/db0) + + +According to the **[official repo](https://github.com/unjs/db0)**, db0 is a lightweight SQL connector designed to work with any compatible SQL database. +It provides a single `Database` interface that works across multiple database engines via connectors. + +Drizzle auto-detects the dialect (PostgreSQL or SQLite) from the db0 connector — no extra configuration needed. + + +Drizzle's `drizzle-orm/db0` driver currently supports db0 dialects: `sqlite` / `libsql` and `postgresql`. + +MySQL is not implemented yet (using a db0 MySQL connector will throw). + + + +**Available db0 connectors:** +`better-sqlite3`, `bun-sqlite`, `cloudflare-d1`, `libsql`, `postgresql`, `pglite` and more. +See the full list at [db0.unjs.io/connectors](https://db0.unjs.io/connectors). + + +#### Step 1 - Install packages + + +drizzle-orm db0 +-D drizzle-kit + + +You also need to install the **underlying driver package** for the db0 connector you plan to use. For example, for `db0/connectors/better-sqlite3`: + + +better-sqlite3 + + +#### Step 2 - Initialize the driver and make a query + + +```typescript copy +import { createDatabase } from 'db0'; +import betterSqlite3 from 'db0/connectors/better-sqlite3'; +import { drizzle } from 'drizzle-orm/db0'; + +const db0 = createDatabase(betterSqlite3({ name: 'sqlite.db' })); +const db = drizzle(db0); + +const result = await db.select().from(...); +``` +```typescript copy +import { createDatabase } from 'db0'; +import postgresql from 'db0/connectors/postgresql'; +import { drizzle } from 'drizzle-orm/db0'; + +const db0 = createDatabase(postgresql({ url: process.env.DATABASE_URL })); +const db = drizzle(db0); + +const result = await db.select().from(...); +``` + + +If you need to provide your existing driver: + +```typescript copy +import type { Database } from 'db0'; +import { drizzle } from 'drizzle-orm/db0'; + +const db0: Database = getDb0Instance(); // your existing db0 instance +const db = drizzle({ client: db0 }); + +const result = await db.select().from(...); +``` + +#### Migrations + +Since db0 supports multiple dialects, make sure to import the migrator matching your connector's dialect: + + +```typescript copy +import { migrate } from 'drizzle-orm/db0/pg/migrator'; + +await migrate(db, { migrationsFolder: './drizzle' }); +``` +```typescript copy +import { migrate } from 'drizzle-orm/db0/sqlite/migrator'; + +await migrate(db, { migrationsFolder: './drizzle' }); +``` + + +#### What's next? + + diff --git a/src/content/docs/connect-overview.mdx b/src/content/docs/connect-overview.mdx index 9ae31357..b6c9d450 100644 --- a/src/content/docs/connect-overview.mdx +++ b/src/content/docs/connect-overview.mdx @@ -175,10 +175,11 @@ Feel free to check out per-driver documentations ["React Native SQLite", "/docs/connect-react-native-sqlite"], ]} /> - From 2b7e67b08172ba3eb51baa1443083dc17f1554bc Mon Sep 17 00:00:00 2001 From: onmax Date: Sat, 7 Feb 2026 12:52:50 +0100 Subject: [PATCH 2/4] test: fix snake import --- tests/snake.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/snake.test.ts b/tests/snake.test.ts index e816c745..da2e4909 100644 --- a/tests/snake.test.ts +++ b/tests/snake.test.ts @@ -3,7 +3,7 @@ import { describe, expect, test } from "vitest"; import { gameSegments, mapSnake, -} from "../components/landing/header/snake/mapSnake"; +} from "../src/ui/components/landing/snake/mapSnake"; const gridHeight = 10; const gridWidth = 19; From 0a2a9e8c26ab8579ea49f97b561726f5b3a5c207 Mon Sep 17 00:00:00 2001 From: onmax Date: Sat, 7 Feb 2026 14:06:40 +0100 Subject: [PATCH 3/4] docs: add db0 correctness note --- src/content/docs/connect-db0.mdx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/content/docs/connect-db0.mdx b/src/content/docs/connect-db0.mdx index 08fd9900..fbf42973 100644 --- a/src/content/docs/connect-db0.mdx +++ b/src/content/docs/connect-db0.mdx @@ -22,6 +22,19 @@ Drizzle's `drizzle-orm/db0` driver currently supports db0 dialects: `sqlite` / ` MySQL is not implemented yet (using a db0 MySQL connector will throw). + +**Correctness note (joins/aliases):** +Drizzle expects drivers to return rows in a stable column order. + +db0's public API returns **object rows** for most connectors, which can collapse duplicate column names (common with joins/aliases) and make results ambiguous. + +For correct join/alias results, use a connector that can return **array-mode rows**: +- SQLite: `db0/connectors/better-sqlite3` (uses `raw(true)` internally) +- PostgreSQL: `db0/connectors/pglite` (uses `rowMode: 'array'` when available) + +Other connectors may throw for complex selections (or return incorrect results) when object rows can’t be mapped safely. + + **Available db0 connectors:** `better-sqlite3`, `bun-sqlite`, `cloudflare-d1`, `libsql`, `postgresql`, `pglite` and more. From 3b4487455314b28d8b4beb70b23b161bbc84cf3d Mon Sep 17 00:00:00 2001 From: onmax Date: Sat, 7 Feb 2026 17:32:42 +0100 Subject: [PATCH 4/4] docs: clarify db0 availability --- src/content/docs/connect-db0.mdx | 34 +++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/content/docs/connect-db0.mdx b/src/content/docs/connect-db0.mdx index fbf42973..73baba48 100644 --- a/src/content/docs/connect-db0.mdx +++ b/src/content/docs/connect-db0.mdx @@ -16,6 +16,11 @@ It provides a single `Database` interface that works across multiple database en Drizzle auto-detects the dialect (PostgreSQL or SQLite) from the db0 connector — no extra configuration needed. + +**Availability:** `drizzle-orm/db0` is landing via **[drizzle-team/drizzle-orm#5296](https://github.com/drizzle-team/drizzle-orm/pull/5296)**. +If `import { drizzle } from 'drizzle-orm/db0'` fails, your installed `drizzle-orm` version doesn’t include this driver yet (this page targets the `beta` docs track). + + Drizzle's `drizzle-orm/db0` driver currently supports db0 dialects: `sqlite` / `libsql` and `postgresql`. @@ -24,15 +29,15 @@ MySQL is not implemented yet (using a db0 MySQL connector will throw). **Correctness note (joins/aliases):** -Drizzle expects drivers to return rows in a stable column order. +The `drizzle-orm/db0` driver expects rows in a stable column order. -db0's public API returns **object rows** for most connectors, which can collapse duplicate column names (common with joins/aliases) and make results ambiguous. +db0's public API returns **object rows** for most connectors. This can collapse duplicate column names (common with joins/aliases) and make results ambiguous. -For correct join/alias results, use a connector that can return **array-mode rows**: -- SQLite: `db0/connectors/better-sqlite3` (uses `raw(true)` internally) -- PostgreSQL: `db0/connectors/pglite` (uses `rowMode: 'array'` when available) +For correct join/alias results, use a connector that lets the driver read **array-mode rows**: +- SQLite: `db0/connectors/better-sqlite3` (driver uses `raw(true)` when available) +- PostgreSQL: `db0/connectors/pglite` (driver uses `rowMode: 'array'` when available) -Other connectors may throw for complex selections (or return incorrect results) when object rows can’t be mapped safely. +If array-mode rows aren’t available and object rows can’t be mapped safely, Drizzle throws a fail-fast error instead of returning potentially wrong data. See **[drizzle-team/drizzle-orm#5296](https://github.com/drizzle-team/drizzle-orm/pull/5296)**. @@ -48,12 +53,27 @@ drizzle-orm db0 -D drizzle-kit -You also need to install the **underlying driver package** for the db0 connector you plan to use. For example, for `db0/connectors/better-sqlite3`: +You also need to install the **underlying driver package** for the db0 connector you plan to use. For example: + +For `db0/connectors/better-sqlite3`: better-sqlite3 +For `db0/connectors/postgresql`: + + +pg +-D @types/pg + + +For `db0/connectors/pglite`: + + +@electric-sql/pglite + + #### Step 2 - Initialize the driver and make a query