DEV Community

Discussion on: Dynamically generating SQL queries using Node.js

Collapse
 
ivan_paqmind profile image
Ivan Kleshnin • Edited

Another question. Why valueList and other similar functions support only primitive values?

Is TypeScript a reason? The thing I like about pg driver is that, unlike MySQL, I can SELECT or INSERT a date, a boolean, an object, etc. value an it will do "the right thing" without an extra hassle.

Maybe it's not entirely safe or somehow "not a good practice" – I dunno.
For now, the API feels limiting for no obvious reason.

Collapse
 
gajus profile image
Gajus Kuizinas

Value token can be any primitive that is shared between pg and JavaScript (string, integer, float, boolean, null).

If you have a requirement for automatic coalescing of other object types (such as Date), I suggest raising an issue. I cannot think of other types that would be relatively safe to cast, though.

Collapse
 
ivan_paqmind profile image
Ivan Kleshnin

JS Object with JSON.stringify?

Thread Thread
 
gajus profile image
Gajus Kuizinas

Too many edges cases where an object could be passed accidentally inserting potentially sensitive data to the database.

There is sql.json() for that, though.