drizzle-orm
drizzle-orm copied to clipboard
[BUG]: No way to use `bun:sqlite` together with dirzzle-kit
What version of drizzle-orm
are you using?
v0.29.0
What version of drizzle-kit
are you using?
v0.20.1
Describe the Bug
Ran the following command where driver
is set to bun:sqlite
:
$ bun drizzle-kit push:sqlite
No config path provided, using default path
Reading config file '/Users/knarf/projects/git-repo-backup/drizzle.config.ts'
Invalid input Either "turso", "libsql", "better-sqlite" are available options for "--driver"
error: "drizzle-kit" exited with code 1 (SIGHUP)
Expected behavior
For this to work when running with bun drizzle-kit
Environment & setup
No response
I'm using bun + drizzle-kit. it's very quick to use push:sqlite to change tables in dev environment. Is there any progress here?
using driver: "better-sqlite",
seems working just fine with bun sqlite
@rifaldhiaw How did you configure it exactly? It tells me "url" is a required option for driver "better-sqlite"
but bun:sqlite doesnt have a url
I also dont know how to use bun:sqlite with Drizzle Kit / Drizzle Studio.
This issue is 1,5 years old. I wonder if Drizzle is still in development or where the focus lies? @dankochetov
Another related issue (maybe a duplicate) with 10 upvotes: #1795 Also related: https://github.com/drizzle-team/drizzle-bun/issues/5
P.S. The same goes for Vercel and Neon -> Why cant I use this drivers within drizzle.config ? Issue: #1612
@dankochetov Will drizzle team fully implement support for Bun SQLite in Drizzle Kit?
@AndriiSherman @dankochetov
I confirm that drizzle studio does not work with bun:sqlite
Please install either 'better-sqlite3' or '@libsql/client' for Drizzle Kit to connect to SQLite databases
error: script "db:studio" exited with code 1
still an issue haha
There seems to be some development within Drizzle but I dont feel they look at any Github issues at all. For example I had an open issue which they fixed "by accident" but they didnt close my issue or reacted in any way.
I found the solution in bunjs docs here
just add this:
// database/index.ts
import { drizzle } from 'drizzle-orm/bun-sqlite';
import { Database } from 'bun:sqlite';
import { migrate } from 'drizzle-orm/bun-sqlite/migrator';
const sqlite = new Database('sqlite.db');
const db = drizzle(sqlite);
migrate(db, { migrationsFolder: './drizzle' });
export { db };
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
dialect: 'sqlite',
schema: './src/lib/server/database/schema.ts',
out: './drizzle',
dbCredentials: {
url: 'file:./sqlite.db'
}
});
run bunx drizzle-kit generate
to generate migrations in ./drizzle
and everything should be fine
edit: you need to restart your dev server to load the migration 😑
bunx drizzle-kit studio
seems to be working for me on latest drizzle-kit
and bun
with following config.
{
"dialect": "sqlite",
"schema": "./data/schema.js",
"out": "./drizzle",
"dbCredentials": {
"url": "file:./data/db.sqlite"
},
"verbose": "true"
}
bunx drizzle-kit studio
seems to be working for me on latestdrizzle-kit
andbun
with following config.{ "dialect": "sqlite", "schema": "./data/schema.js", "out": "./drizzle", "dbCredentials": { "url": "file:./data/db.sqlite" }, "verbose": "true" }
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
dialect: 'sqlite',
schema: './src/db/schema.ts',
out: './src/db/migrations',
dbCredentials: {
url: './data/db/app.db',
},
verbose: true,
})
Please install either 'better-sqlite3' or '@libsql/client' for Drizzle Kit to connect to SQLite databases
I get that with drizzle-kit studio
command @doroved, but with bun drizzle-kit studio
or bunx drizzle-kit studio
it's working.
Please install either 'better-sqlite3' or '@libsql/client' for Drizzle Kit to connect to SQLite databases
I think better-sqlite3
is unnecessary for bun:sqlite
. However, the generate
command checks for the existence of better-sqlite3
or @libsql/client
to do the job when the dialect is SQLite. I had to install better-sqlite3
only to satisfy the generate
command, even though I don't use it.
For anyone needing a working configuration, here's mine:
// db.ts
import { Database } from 'bun:sqlite';
import { drizzle } from 'drizzle-orm/bun-sqlite';
import * as schema from '@/db/schema';
const sqlite = new Database();
export const db = drizzle(sqlite, { schema });
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
dbCredentials: {
url: 'file:path/to/local.db',
},
dialect: 'sqlite',
out: './src/db/migrations',
schema: './src/db/schema.ts',
});
Bun natively implements a high-performance SQLite3 driver. And it is already usable with Drizzle. Why should we install another third party sqlite driver just for Drizzle Kit?
The issue is marked as a bug but please consider this as a feature request to support both Bun Database and Bun native driver bun:sqlite
.
I can confirm introspect
and push
refuse to work with bun SQLite.
bunx drizzle-kit introspect
drizzle-kit: v0.23.0
drizzle-orm: v0.32.0
No config path provided, using default path
Reading config file '<file>'
Pulling from ['public'] list of schemas
Please install either 'better-sqlite3' or '@libsql/client' for Drizzle Kit to connect to SQLite databases
Also worth noting that even after installing better-sqlite3
push
still fails.
TypeError: This statement does not return data. Use run() instead
migrate
did seem to work.
I'll also add that better-sqlite3
requires python to be installed, which I found out when testing pushing to production. So not only does better-sqlite3
need to be unnecessarily installed, so does python
.