fuxingZhang / postgres

PostgreSQL client for node.js.
MIT License
2 stars 1 forks source link

There is no parameter $1 #1

Closed Khaled-Ch closed 3 years ago

Khaled-Ch commented 3 years ago

I am using node-postgress version 0.6.2 When I am running the following query

await pool.query( 'SELECT id, email from user where name = $1', ['jone'], );

I am getting this error

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Message { name: 'error', message: 'there is no parameter $1', severity: 'ERROR', code: '42P02', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: '/home/ec2-user/padb/src/pg/src/backend/parser/parse_expr.c', line: '477', routine: 'transformExpr' })

However, If I run the same query with this format it works as expected

await pool.query( SELECT id, email from user where name = '${username}' );

NodeJs version is v14.17.3

fuxingZhang commented 3 years ago

This repository does not support Parameterized query.

You can use the best library(9.9k star +): https://github.com/brianc/node-postgres

docs: https://node-postgres.com/

const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()