Is this error in Docs for drizzle-kit Running Migrations SQLite
In the following link: https://orm.drizzle.team/kit-docs/overview, it states at the end of the code block for Running Migrations SQLite to write "betterSqlite.close()". However, it closes the database. The code block works when you omit "betterSqlite.close()". According to chatgpt: It appears that the better-sqlite3 package automatically closes the database connection when it is garbage collected or when the Node.js process exits. Therefore, explicitly calling betterSqlite.close() is not necessary in most cases.
Is this an error in the docs or is there a reason for inserting "betterSqlite.close()"? If there is a reason for inserting "betterSqlite.close()" how can we mitigate it closing the database when we run our code. Thanks!
5 Replies
Did you use
await
when using migrate
? It may close the connection before the action is executed.
The connection is closed otherwise the script might hungNo, I followed the docs in the link for SQLite
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import * as schema from "./schema";
export const sqlite = new Database("dev.db");
sqlite.pragma("journal_mode = WAL");
export const db = drizzle(sqlite, { schema });
migrate(db, { migrationsFolder: "drizzle" });
Try to use
await
and see how it goes. It seems weird it is not used there..
Oh wait, maybe the migrate
for sqlite is synchronous?In my ide I get the following typescript error: 'await' has no effect on the type of this expression.ts(80007)
Yeah, sqlite
migrate
is synchronous and no await is necessary. Then I guess you might be right and could ask on GitHub about this 😀