Skip to content

$queryRaw ignores schema when using @prisma/adapter-pg #24660

@rstreefland

Description

@rstreefland

Hi, I've been experimenting using the new driverAdapters preview feature with @prisma/adapter-pg so I can use oauth2 token login for Google Cloud SQL which is not currently supported out of the box by prisma.

Our database does not use the public schema, rather it uses one called staging. When using the built in prisma queries, they succeed as expected. However, when I use $queryRaw, raw queries that previously didn't need to be prepended with the schema now fail.

This is my code to instantiate the prisma client:

import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@prisma/client";
import { GoogleAuth } from "google-auth-library";
import { Pool } from "pg";

const auth = new GoogleAuth({
  scopes: ["https://www.googleapis.com/auth/sqlservice.login"],
});

const pool = new Pool({
  host: "/cloudsql/REDACTED",
  user: "REDACTED",
  password: async (): Promise<string> => {
    return (await auth.getAccessToken()) as string;
  },
  database: "uat",
  ssl: false,
  idleTimeoutMillis: 0,
  max: 5,
});

const adapter = new PrismaPg(pool, {
  schema: "staging",
});

export const prismaClient = new PrismaClient({
  adapter,
  log: ["info", "warn", "error"],
});

This raw query works without the PrismaPg adapter, but fails when I use the adapter:

 await prismaClient.$queryRaw`select * from "AccountingPeriod" limit 1`;

It produces these logs:
Screenshot 2024-06-27 at 10 40 29

This raw query succeeds when using the PrismaPg adapter:

 await prismaClient.$queryRaw`select * from staging."AccountingPeriod" limit 1`;

I'm happy to provide more information if needed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.tech/enginesIssue for tech Engines.topic: driverAdapterstopic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions