async function emptyDBTables(db: PlanetScaleDatabase<typeof schema>) {
console.log("๐๏ธ Emptying the entire database");
const tablesSchema = db._.schema;
if (!tablesSchema) throw new Error("Schema not loaded");
const queries = Object.values(tablesSchema).map((table) => {
console.log(`๐งจ Preparing delete query for table: ${table.dbName}`);
return sql.raw(`DELETE FROM ${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");
}
async function emptyDBTables(db: PlanetScaleDatabase<typeof schema>) {
console.log("๐๏ธ Emptying the entire database");
const tablesSchema = db._.schema;
if (!tablesSchema) throw new Error("Schema not loaded");
const queries = Object.values(tablesSchema).map((table) => {
console.log(`๐งจ Preparing delete query for table: ${table.dbName}`);
return sql.raw(`DELETE FROM ${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");
}