P
Prisma7d ago
Dario

Issues with raw queries (was working) - Postgres

Hi everyone, I've a very weird issue within my setup, it was working but since the switch from npm to Yarn (but I think is not related) I'm facing this issue with a very simple script:
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function testDatabaseConnection() {
try {
const ormTest = await prisma.pipeline.findFirst();
console.log('ORM query result:', ormTest);

const simpleTest = await prisma.$queryRaw`SELECT 1`;
console.log('Simple query result:', simpleTest);

const parameterizedTest = await prisma.$queryRaw`
SELECT *
FROM "pipeline"
WHERE "experiment_name" = ${'Test'}
LIMIT 1
`;
console.log('Parameterized query result:', parameterizedTest);
} catch (e) {
console.error('Error executing query:', e);
}
}

testDatabaseConnection();
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function testDatabaseConnection() {
try {
const ormTest = await prisma.pipeline.findFirst();
console.log('ORM query result:', ormTest);

const simpleTest = await prisma.$queryRaw`SELECT 1`;
console.log('Simple query result:', simpleTest);

const parameterizedTest = await prisma.$queryRaw`
SELECT *
FROM "pipeline"
WHERE "experiment_name" = ${'Test'}
LIMIT 1
`;
console.log('Parameterized query result:', parameterizedTest);
} catch (e) {
console.error('Error executing query:', e);
}
}

testDatabaseConnection();
I'm getting this error:
ORM query result: {
...
}
Error executing query: TypeError: Cannot read properties of undefined (reading 'length')
at xm (/app/node_modules/@prisma/client/runtime/library.js:121:5004)
at _l (/app/node_modules/@prisma/client/runtime/library.js:121:4810)
at $n.unpack (/app/node_modules/@prisma/client/runtime/library.js:121:8042)
at $n.mapQueryEngineResult (/app/node_modules/@prisma/client/runtime/library.js:121:6509)
at Object.singleLoader (/app/node_modules/@prisma/client/runtime/library.js:121:5927)
at async $n.request (/app/node_modules/@prisma/client/runtime/library.js:121:6194)
at async l (/app/node_modules/@prisma/client/runtime/library.js:130:9633)
at async testDatabaseConnection (/app/testDb.js:11:24) {
clientVersion: '5.22.0'
}
ORM query result: {
...
}
Error executing query: TypeError: Cannot read properties of undefined (reading 'length')
at xm (/app/node_modules/@prisma/client/runtime/library.js:121:5004)
at _l (/app/node_modules/@prisma/client/runtime/library.js:121:4810)
at $n.unpack (/app/node_modules/@prisma/client/runtime/library.js:121:8042)
at $n.mapQueryEngineResult (/app/node_modules/@prisma/client/runtime/library.js:121:6509)
at Object.singleLoader (/app/node_modules/@prisma/client/runtime/library.js:121:5927)
at async $n.request (/app/node_modules/@prisma/client/runtime/library.js:121:6194)
at async l (/app/node_modules/@prisma/client/runtime/library.js:130:9633)
at async testDatabaseConnection (/app/testDb.js:11:24) {
clientVersion: '5.22.0'
}
ORM works fine, wherever I try to use a RAW query, even simplest one, doesn't work, any clue?
3 Replies
Yetzederixx
Yetzederixx7d ago
I had issues with raw queries a while back, ended up switching to this instead https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql I don't know if it'll solve your problem, but it did mine
Writing Type-safe SQL with TypedSQL and Prisma Client | Prisma Docu...
Learn how to use TypedSQL to write fully type-safe SQL queries that are compatible with any SQL console and Prisma Client.
Yetzederixx
Yetzederixx7d ago
I know it'd be annoying to have a folder, and query, just for a select 1 statement... but it may be worth a shot
RaphaelEtim
RaphaelEtim6d ago
Hi @Dario Can you please share the schema file so i can try reproducing it?
Want results from more Discord servers?
Add your server