Created
November 6, 2023 09:59
-
-
Save ThimoDEV/b071dc83308d6b0a5e165efb6efa4902 to your computer and use it in GitHub Desktop.
Revisions
-
ThimoDEV created this gist
Nov 6, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ // db.ts import * as schema from "./schema" export const db = drizzle(connection, { schema }) //reset.ts async function reset() { const tableSchema = db._.schema if (!tableSchema) { throw new Error("No table schema found") } console.log("🗑️ Emptying the entire database") const queries = Object.values(tableSchema).map((table) => { console.log(`🧨 Preparing delete query for table: ${table.dbName}`) return sql.raw(`TRUNCATE TABLE ${table.dbName};`) }) console.log("📨 Sending delete queries...") await db.transaction(async (tx) => { await Promise.all( queries.map(async (query) => { if (query) await tx.execute(query) }) ) }) console.log("✅ Database emptied") } reset().catch((e) => { console.error(e) })