DT
Drizzle Team•17mo ago
Meexa

Drizzle can't find local sqlite file

I'm trying to play around with sqlite but I can't seem to connect my config and local sqlite db file. Config:
import type { Config } from 'drizzle-kit';

export default {
schema: './src/db/schema.ts',
out: './drizzle',
driver: 'better-sqlite',
dbCredentials: {
url: 'file:./sqlite.db',
},
verbose: true,
} satisfies Config;
import type { Config } from 'drizzle-kit';

export default {
schema: './src/db/schema.ts',
out: './drizzle',
driver: 'better-sqlite',
dbCredentials: {
url: 'file:./sqlite.db',
},
verbose: true,
} satisfies Config;
The sqlite db file is in the root of my project, just like the drizzle config I've also set up this file in src/db/index.ts
import Database from 'better-sqlite3';
import { BetterSQLite3Database, drizzle } from 'drizzle-orm/better-sqlite3';

const sqlite = new Database('sqlite.db');
export const db: BetterSQLite3Database = drizzle(sqlite);
import Database from 'better-sqlite3';
import { BetterSQLite3Database, drizzle } from 'drizzle-orm/better-sqlite3';

const sqlite = new Database('sqlite.db');
export const db: BetterSQLite3Database = drizzle(sqlite);
Error:
> drizzle-kit push:sqlite

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/___/Documents/personal/classic-armory/drizzle.config.ts'
drizzle-kit: v0.19.12
drizzle-orm: v0.28.2

/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:59
throw new TypeError('Cannot open database because the directory does not exist');
^

TypeError: Cannot open database because the directory does not exist
at new Database (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:59:9)
at connectToSQLite (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:51793:36)
at async Command.<anonymous> (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:53315:22)

Node.js v18.12.1
> drizzle-kit push:sqlite

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/___/Documents/personal/classic-armory/drizzle.config.ts'
drizzle-kit: v0.19.12
drizzle-orm: v0.28.2

/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:59
throw new TypeError('Cannot open database because the directory does not exist');
^

TypeError: Cannot open database because the directory does not exist
at new Database (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:59:9)
at connectToSQLite (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:51793:36)
at async Command.<anonymous> (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:53315:22)

Node.js v18.12.1
3 Replies
Meexa
MeexaOP•17mo ago
I also can't find much in the docs on how to work with a local sqlite file 😦 generate:sqlite seems to work but not push:sqlite
jackaltd
jackaltd•17mo ago
Try this: dbCredentials: { url: './sqlite.db', }
Andrii Sherman
Andrii Sherman•17mo ago
this one should work
Want results from more Discord servers?
Add your server