OSCAR
OSCAR
DTDrizzle Team
Created by Louistiti on 7/18/2023 in #help
Clear the whole database?
I was not able to use the execute function, so I did the following
async function clearDataBase(db:LibSQLDatabase<typeof schema>) {

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 table.tsName
})
console.log(queries);
queries.forEach(async (query) => {
const schemaToDelete = schema[query];
if (!schemaToDelete) throw new Error(`No schema found for ${query}`);
await db.delete(schemaToDelete);
});
}
async function clearDataBase(db:LibSQLDatabase<typeof schema>) {

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 table.tsName
})
console.log(queries);
queries.forEach(async (query) => {
const schemaToDelete = schema[query];
if (!schemaToDelete) throw new Error(`No schema found for ${query}`);
await db.delete(schemaToDelete);
});
}
The variable schema is defined as
import * as schema from "./turso/schemas/index";
import * as schema from "./turso/schemas/index";
Where I export all the schemas used
59 replies