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

[BUG]: No way to use bun:sqlite together with dirzzle-kit #1520

Open
TheKnarf opened this issue Nov 16, 2023 · 19 comments · May be fixed by #3893
Open

[BUG]: No way to use bun:sqlite together with dirzzle-kit #1520

TheKnarf opened this issue Nov 16, 2023 · 19 comments · May be fixed by #3893
Labels
driver/bun-sqlite drizzle/kit enhancement New feature or request priority Will be worked on next

Comments

@TheKnarf
Copy link

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

@TheKnarf TheKnarf added the bug Something isn't working label Nov 16, 2023
@dinfer
Copy link

dinfer commented Nov 25, 2023

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?

@rifaldhiaw
Copy link

using driver: "better-sqlite", seems working just fine with bun sqlite

@MickL
Copy link

MickL commented Apr 22, 2024

@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

@MickL
Copy link

MickL commented Apr 22, 2024

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: drizzle-team/drizzle-bun#5

P.S. The same goes for Vercel and Neon -> Why cant I use this drivers within drizzle.config ? Issue: #1612

@keisanng
Copy link

keisanng commented May 1, 2024

@dankochetov Will drizzle team fully implement support for Bun SQLite in Drizzle Kit?

@MickL
Copy link

MickL commented May 4, 2024

@doroved
Copy link

doroved commented May 9, 2024

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

@StevenStavrakis
Copy link

still an issue haha

@MickL
Copy link

MickL commented Jun 13, 2024

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.

@IslamZaoui
Copy link

IslamZaoui commented Jun 20, 2024

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 😑

@fo-rk
Copy link

fo-rk commented Jul 2, 2024

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"
}

@doroved
Copy link

doroved commented Jul 3, 2024

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"
}
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

@fo-rk
Copy link

fo-rk commented Jul 3, 2024

I get that with drizzle-kit studio command @doroved, but with bun drizzle-kit studio or bunx drizzle-kit studio it's working.

@shmshd
Copy link

shmshd commented Jul 16, 2024

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',
});

@MickL
Copy link

MickL commented Jul 16, 2024

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.

@jazoom
Copy link

jazoom commented Jul 20, 2024

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

@jazoom
Copy link

jazoom commented Jul 20, 2024

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.

@jazoom
Copy link

jazoom commented Aug 28, 2024

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.

@L-Mario564 L-Mario564 added enhancement New feature or request driver/bun-sqlite priority Will be worked on next and removed bug Something isn't working labels Oct 17, 2024
@psi-4ward
Copy link

I wonder why this seems so challenging to implement. Did anyone took a deeper look and can outline the blockers?

loss-and-quick added a commit to loss-and-quick/drizzle-orm that referenced this issue Jan 3, 2025
loss-and-quick added a commit to loss-and-quick/drizzle-orm that referenced this issue Jan 3, 2025
loss-and-quick added a commit to loss-and-quick/drizzle-orm that referenced this issue Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
driver/bun-sqlite drizzle/kit enhancement New feature or request priority Will be worked on next
Projects
None yet
Development

Successfully merging a pull request may close this issue.