Home / Function/ setupRemoteDb() — astro Function Reference

setupRemoteDb() — astro Function Reference

Architecture documentation for the setupRemoteDb() function in test-utils.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  ebfbc6f0_cd93_d1f3_6f95_caa77b2b7255["setupRemoteDb()"]
  9c9ba75b_c6f1_7d10_d247_9a1ccac73501["test-utils.js"]
  ebfbc6f0_cd93_d1f3_6f95_caa77b2b7255 -->|defined in| 9c9ba75b_c6f1_7d10_d247_9a1ccac73501
  style ebfbc6f0_cd93_d1f3_6f95_caa77b2b7255 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/db/test/test-utils.js lines 12–67

export async function setupRemoteDb(astroConfig, options = {}) {
	const url = isWindows
		? new URL(`./.astro/${Date.now()}.db`, astroConfig.root)
		: new URL(`./${Date.now()}.db`, astroConfig.root);
	const token = 'foo';
	process.env.ASTRO_DB_REMOTE_URL = url.toString();
	if (!options.useDbAppTokenFlag) {
		process.env.ASTRO_DB_APP_TOKEN = token;
	}
	process.env.ASTRO_INTERNAL_TEST_REMOTE = true;

	if (isWindows) {
		await mkdir(new URL('.', url), { recursive: true });
	}

	const dbClient = createClient({
		url,
		authToken: token,
	});

	const { dbConfig } = await resolveDbConfig(astroConfig);
	const setupQueries = [];
	for (const [name, table] of Object.entries(dbConfig?.tables ?? {})) {
		const createQuery = getCreateTableQuery(name, table);
		const indexQueries = getCreateIndexQueries(name, table);
		setupQueries.push(createQuery, ...indexQueries);
	}

	for (const sql of setupQueries) {
		await dbClient.execute({
			sql,
			args: [],
		});
	}

	await cli({
		config: astroConfig,
		flags: {
			_: [undefined, 'astro', 'db', 'execute', 'db/seed.ts'],
			remote: true,
			...(options.useDbAppTokenFlag ? { dbAppToken: token } : {}),
		},
	});

	return {
		async stop() {
			delete process.env.ASTRO_DB_REMOTE_URL;
			delete process.env.ASTRO_DB_APP_TOKEN;
			delete process.env.ASTRO_INTERNAL_TEST_REMOTE;
			dbClient.close();
			if (!isWindows) {
				await unlink(url);
			}
		},
	};
}

Domain

Subdomains

Frequently Asked Questions

What does setupRemoteDb() do?
setupRemoteDb() is a function in the astro codebase, defined in packages/db/test/test-utils.js.
Where is setupRemoteDb() defined?
setupRemoteDb() is defined in packages/db/test/test-utils.js at line 12.

Analyze Your Own Codebase

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

Try Supermodel Free