DT
Drizzle Team•11mo 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:
> classic-armory@0.1.0 db:push
> 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/better-sqlite3@8.5.0/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/better-sqlite3@8.5.0/node_modules/better-sqlite3/lib/database.js:59:9)
at connectToSQLite (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/drizzle-kit@0.19.12/node_modules/drizzle-kit/index.cjs:51793:36)
at async Command.<anonymous> (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/drizzle-kit@0.19.12/node_modules/drizzle-kit/index.cjs:53315:22)

Node.js v18.12.1
> classic-armory@0.1.0 db:push
> 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/better-sqlite3@8.5.0/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/better-sqlite3@8.5.0/node_modules/better-sqlite3/lib/database.js:59:9)
at connectToSQLite (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/drizzle-kit@0.19.12/node_modules/drizzle-kit/index.cjs:51793:36)
at async Command.<anonymous> (/Users/___/Documents/personal/classic-armory/node_modules/.pnpm/drizzle-kit@0.19.12/node_modules/drizzle-kit/index.cjs:53315:22)

Node.js v18.12.1
3 Replies
Meexa
Meexa•11mo 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•11mo ago
Try this: dbCredentials: { url: './sqlite.db', }
Andrii Sherman
Andrii Sherman•11mo ago
this one should work
Want results from more Discord servers?
Add your server
More Posts
How to debug Drizzle queriesI'm executing an insert on a table, I'm gettin no errors, and yet the data is not being saved to theTypeError: Cannot read properties of undefined (reading 'referencedTable')Here is the relational query that I'm trying to execute (Turso SQLite): ```javascript const result =Querying with two consecutive WITH causes error "the table is not part of the query"I created my query by stages. I create a part, check it's result via await and .all() then I turn it[Fixed] - Next.js remaining connection slots are reserved for non-replication superuser connectionsI am frequently getting the above error. Database: Supabase Github: https://github.com/ShaikRehan12[drizzle-zod] How to make all fields of a schema derived from a table required ?I just tried the plugin and I'm happy to move from manually creating zod schemas. However, I came inIs there a way to declare a custom SQL index?I'm trying to create an index on the lowercase value of a column using Postgres. I tried ```js uniqHow should I set this up?https://gist.github.com/barrybtw/f4c54bf7bdac98af34069363d7b1be87sqlite code first with in-memory dbHey, I thought it'd be rather easy to create a schema from scratch without running a "migration" (frDrizzle-Kit: incorrect schema.ts being usedI have some schema files in a subfolder. I have referenced the path in the drizzle.config.ts, but inGroup by Multiple columns with drizzleI have a schema that looks rougly like this: ```date | location | name | quantity``` I want to gro