Home / Function/ recreateTables() — astro Function Reference

recreateTables() — astro Function Reference

Architecture documentation for the recreateTables() function in vite-plugin-db.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  dd29af9e_6b76_c953_7091_c9ee6b0f8ac9["recreateTables()"]
  10c96ff6_9978_85bd_85f5_ced507d506e2["vite-plugin-db.ts"]
  dd29af9e_6b76_c953_7091_c9ee6b0f8ac9 -->|defined in| 10c96ff6_9978_85bd_85f5_ced507d506e2
  54a8b5c7_dd97_53d0_6372_b72f4f1ba7ee["vitePluginDb()"]
  54a8b5c7_dd97_53d0_6372_b72f4f1ba7ee -->|calls| dd29af9e_6b76_c953_7091_c9ee6b0f8ac9
  style dd29af9e_6b76_c953_7091_c9ee6b0f8ac9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/db/src/core/integration/vite-plugin-db.ts lines 267–282

async function recreateTables({ tables, root }: { tables: LateTables; root: URL }) {
	const { ASTRO_DATABASE_FILE } = getAstroEnv();
	const dbUrl = normalizeDatabaseUrl(ASTRO_DATABASE_FILE, new URL(DB_PATH, root).href);
	const db = createClient({ url: dbUrl });
	const setupQueries: SQL[] = [];
	for (const [name, table] of Object.entries(tables.get() ?? {})) {
		const dropQuery = sql.raw(`DROP TABLE IF EXISTS ${sqlite.escapeName(name)}`);
		const createQuery = sql.raw(getCreateTableQuery(name, table));
		const indexQueries = getCreateIndexQueries(name, table);
		setupQueries.push(dropQuery, createQuery, ...indexQueries.map((s) => sql.raw(s)));
	}
	await db.batch([
		db.run(sql`pragma defer_foreign_keys=true;`),
		...setupQueries.map((q) => db.run(q)),
	]);
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does recreateTables() do?
recreateTables() is a function in the astro codebase, defined in packages/db/src/core/integration/vite-plugin-db.ts.
Where is recreateTables() defined?
recreateTables() is defined in packages/db/src/core/integration/vite-plugin-db.ts at line 267.
What calls recreateTables()?
recreateTables() is called by 1 function(s): vitePluginDb.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free