UW-Macrostrat / macrostrat-api

The API for SCIENCE
3 stars 1 forks source link

More elegant handling of parameters in Postgres queries #158

Open jczaplew opened 8 years ago

jczaplew commented 8 years ago

The syntax for a parameterized query in postgres is $[index of target parameter]. However, when dynamically building SQL queries keeping track of indices can be a bit messy and requires us to do things like sql += 'foo = $' + (params.length + 1). This leads to many opportunities for errors while writing the code and makes it more difficult to reason about.

To fix this, some middleware can be added before larkin.queryPg that automatically substitutes the correct indices.