- I installed `@types/uuid` because typescript required it in a file - In `packages/db-sqlite/src/index.ts` I see four more errors in my IDE that don't appear when I run the typecheck in the CLI with `tsc --noEmit`. The same thing happened in https://github.com/payloadcms/payload/pull/11560. Also referencing https://github.com/payloadcms/payload/pull/11226#issuecomment-2713898801 for traceability.
24 lines
809 B
TypeScript
24 lines
809 B
TypeScript
import type { Row } from '@libsql/client'
|
|
|
|
import type { DropDatabase, SQLiteAdapter } from './types.js'
|
|
|
|
const getTables = (adapter: SQLiteAdapter) => {
|
|
return adapter.client.execute(`SELECT name
|
|
FROM sqlite_master
|
|
WHERE type = 'table'
|
|
AND name NOT LIKE 'sqlite_%';`)
|
|
}
|
|
|
|
const dropTables = (adapter: SQLiteAdapter, rows: Row[]) => {
|
|
const multi = `
|
|
PRAGMA foreign_keys = OFF;\n
|
|
${rows.map(({ name }) => `DROP TABLE IF EXISTS ${name as string}`).join(';\n ')};\n
|
|
PRAGMA foreign_keys = ON;`
|
|
return adapter.client.executeMultiple(multi)
|
|
}
|
|
|
|
export const dropDatabase: DropDatabase = async function ({ adapter }) {
|
|
const result = await getTables(adapter)
|
|
await dropTables(adapter, result.rows)
|
|
}
|