4

What does the $ sign mean in this statement:

// SQL Query > Update Data
client.query('UPDATE items SET text=($1), complete=($2) WHERE id=($3)',
[data.text, data.complete, id]);
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
na3na3iss
  • 65
  • 1
  • 1
  • 10
  • 1
    i'm beginner on node.js for this reason i'm asking this question i know that it is like an Alias but i don't know what it means exactly i spend more than 2 hours to search but i find anything :) – na3na3iss Feb 27 '18 at 16:37

1 Answers1

4

Pretty universally in that context it's called a "placeholder". You got that code from this blog entry. You can see there that client is defined above in the callback to pg.connect,

pg.connect(connectionString, (err, client, done) => {

Looking up in that blog entry, pg is defined here

const pg = require('pg');

You can always find out what an npm-installed module name resolves to by doing a quick search. In this case though the blog openly says they're using node-postgres. Which documents this under,

Paramaterized means accepting of a parameter. That parameter's placement is defined with a "placeholder" as specified with $. The purpose of this is often to save time in planning and to avert SQL Injection attacks.

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • Hi @Evan Carroll i have just a question can you see if you have a response [link] (https://stackoverflow.com/questions/49150477/update-postgreql-database-with-node-js) thank you – na3na3iss Mar 07 '18 at 13:44