Skip to content

Commit

Permalink
make a use query after receiving the initialize schema in planetscale
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 6, 2023
1 parent 662c7bb commit 4a4f468
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ async function handleRequest(method: string, params: unknown): Promise<unknown>
});
await engine.connect("")

await useSchema(engine, castParams.url)

state[castParams.schemaId] = {
engine,
adapter,
Expand Down Expand Up @@ -222,6 +224,20 @@ async function initQe(url: string, prismaSchema: string, logCallback: qe.QueryLo
return [engineInstance, errorCapturingAdapter];
}

async function useSchema(engine: engines.QueryEngineInstance, url: string): Promise<void> {
if (process.env.DRIVER_ADAPTER == 'planetscale') {
const databaseName = new URL(url).pathname.replace("/", "");
console.error("---- Changing database used by proxy to the one specified in the URL: "+databaseName)
let request = {
method: 'executeRaw',
params: {
query: 'USE ' + databaseName + ';',
}
};
await engine.query(JSON.stringify(request), "", "")
}
}

async function adapterFromEnv(url: string): Promise<DriverAdapter> {
const adapter = process.env.DRIVER_ADAPTER ?? ''

Expand Down

0 comments on commit 4a4f468

Please sign in to comment.