- Abstract shared sql code to a new drizzle package - Adds sqlite package, not ready to publish until drizzle patches some issues - Add `transactionOptions` to allow customizing or disabling db transactions - Adds "experimental" label to the `schemaName` property until drizzle patches an issue
22 lines
716 B
TypeScript
22 lines
716 B
TypeScript
import type { DropDatabase } from './types.js'
|
|
|
|
const getTables = (adapter) => {
|
|
return adapter.client.execute(`SELECT name
|
|
FROM sqlite_master
|
|
WHERE type = 'table'
|
|
AND name NOT LIKE 'sqlite_%';`)
|
|
}
|
|
|
|
const dropTables = (adapter, rows) => {
|
|
const multi = `
|
|
PRAGMA foreign_keys = OFF;\n
|
|
${rows.map(({ name }) => `DROP TABLE IF EXISTS ${name}`).join(';\n ')};\n
|
|
PRAGMA foreign_keys = ON;`
|
|
return adapter.client.executeMultiple(multi)
|
|
}
|
|
|
|
export const dropDatabase: DropDatabase = async function dropDatabase({ adapter }) {
|
|
const result = await getTables(adapter)
|
|
await dropTables(adapter, result.rows)
|
|
}
|