getRemoteVirtualModContents() — astro Function Reference
Architecture documentation for the getRemoteVirtualModContents() function in vite-plugin-db.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 8595edb1_700a_631d_5f61_1f6442f606d1["getRemoteVirtualModContents()"] 10c96ff6_9978_85bd_85f5_ced507d506e2["vite-plugin-db.ts"] 8595edb1_700a_631d_5f61_1f6442f606d1 -->|defined in| 10c96ff6_9978_85bd_85f5_ced507d506e2 54a8b5c7_dd97_53d0_6372_b72f4f1ba7ee["vitePluginDb()"] 54a8b5c7_dd97_53d0_6372_b72f4f1ba7ee -->|calls| 8595edb1_700a_631d_5f61_1f6442f606d1 cd7a45b4_c277_8322_6079_4ee060c2e132["getDBModule()"] 8595edb1_700a_631d_5f61_1f6442f606d1 -->|calls| cd7a45b4_c277_8322_6079_4ee060c2e132 22c4d439_15aa_1784_8821_5d5ea7ff98b7["getStringifiedTableExports()"] 8595edb1_700a_631d_5f61_1f6442f606d1 -->|calls| 22c4d439_15aa_1784_8821_5d5ea7ff98b7 style 8595edb1_700a_631d_5f61_1f6442f606d1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/db/src/core/integration/vite-plugin-db.ts lines 188–252
export function getRemoteVirtualModContents({
tables,
appToken,
isBuild,
output,
localExecution,
}: {
tables: DBTables;
appToken: string;
isBuild: boolean;
output: AstroConfig['output'];
/**
* Used for the execute command to import the client directly.
* In other cases, we use the runtime only vite virtual module.
*
* This is used to ensure that the client is imported correctly
* when executing commands like `astro db execute`.
*/
localExecution: boolean;
}) {
const dbInfo = getRemoteDatabaseInfo();
function appTokenArg() {
if (isBuild) {
if (output === 'server') {
// In production build, always read the runtime environment variable.
return `process.env.ASTRO_DB_APP_TOKEN`;
} else {
// Static mode or prerendering needs the local app token.
return `process.env.ASTRO_DB_APP_TOKEN ?? ${JSON.stringify(appToken)}`;
}
} else {
return JSON.stringify(appToken);
}
}
function dbUrlArg() {
const dbStr = JSON.stringify(dbInfo.url);
if (isBuild) {
// Allow overriding, mostly for testing
return `import.meta.env.ASTRO_DB_REMOTE_URL ?? ${dbStr}`;
} else {
return dbStr;
}
}
// If this is for the execute command, we need to import the client directly instead of using the runtime only virtual module.
const clientImport = getDBModule(localExecution);
return `
import {asDrizzleTable} from ${RUNTIME_IMPORT};
${clientImport}
export const db = await createClient({
url: ${dbUrlArg()},
token: ${appTokenArg()},
});
export * from ${RUNTIME_VIRTUAL_IMPORT};
${getStringifiedTableExports(tables)}
`;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getRemoteVirtualModContents() do?
getRemoteVirtualModContents() is a function in the astro codebase, defined in packages/db/src/core/integration/vite-plugin-db.ts.
Where is getRemoteVirtualModContents() defined?
getRemoteVirtualModContents() is defined in packages/db/src/core/integration/vite-plugin-db.ts at line 188.
What does getRemoteVirtualModContents() call?
getRemoteVirtualModContents() calls 2 function(s): getDBModule, getStringifiedTableExports.
What calls getRemoteVirtualModContents()?
getRemoteVirtualModContents() 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