Skip to content

Support prepared statements #23

@orangemug

Description

@orangemug

A prepared statement is a server-side object that can be used to optimize performance. When the PREPARE statement is executed, the specified statement is parsed, analyzed, and rewritten. When an EXECUTE command is subsequently issued, the prepared statement is planned and executed. This division of labor avoids repetitive parse analysis work, while allowing the execution plan to depend on the specific parameter values supplied. - https://www.postgresql.org/docs/9.2/static/sql-prepare.html

Other implementations

Basically in short anything that only uses ? can be prepared ahead of time.

What this means for SQL stamp is that

  • {=key, optionalDefault} stays as is
  • {!key, optionalDefault} changed in the prepare step and will now error if altered in the run step
  • {?key, replaceTruthy, replaceFalsey} should be replaced with a ? rather than raw true output
  • {>path, optionalDataKeys*} stays as is

So the API would look something like

var preparedStatment = sqlStamp.prepare(__dirname+"../lib/sql/foo.sql");

// Insert this into the database
var sql = preparedStatment.sql();

// Args to run prepared statement
preparedStatment.getArgs({paramValue: "paramValue"});

We would aim to keep backwards compatibility with the current API for the next few versions

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions