2Toad / node-teradata

Teradata for Node.js
MIT License
6 stars 5 forks source link

Add support for named parameters in prepared statements #26

Closed JasonPierce closed 7 years ago

JasonPierce commented 7 years ago

Currently prepared statements use the Teradata syntax of anonymous parameters referenced by index:

var id = 7;
var username = 'Foo';
var sql = 'UPDATE MyDatabase.MyTable SET Username = ? WHERE Id = ?';

return teradata.writePreparedStatement(sql, [
    teradata.createPreparedStatementParam(1, 'String', username),
    teradata.createPreparedStatementParam(2, 'Int', Number(id))
  ]);

This proposed enhancement adds the ability to name parameters (similar to Sequelize's named replacements):

var id = 7;
var username = 'Foo';
var sql = 'UPDATE MyDatabase.MyTable SET Username = :username WHERE Id = :id';

return teradata.writePreparedStatement(sql, [
    teradata.createPreparedStatementParam('username', 'String', username),
    teradata.createPreparedStatementParam('id', 'Int', Number(id))
  ]);

Acceptance Criteria

  1. Valid chars for a named parameter include: letters, numbers, underscore
  2. Named parameters are case sensitive
  3. Named parameters within the sql must be prefixed with :
  4. writePreparedStatement supports named parameters
  5. readPreparedStatement supports named parameters
  6. createPreparedStatementParam accepts a string as it's first parameter (internally placing it in named parameter mode)
  7. An error is not thrown when createPreparedStatementParam cannot find a matching named parameter within the statement
  8. An error is thrown when the params array (of writePreparedStatement and readPreparedStatement) contains named parameters with duplicate names
  9. An error is thrown when the params array (of writePreparedStatement and readPreparedStatement) contains both anonymous and named parameters
  10. Documentation is updated with named parameter examples
JasonPierce commented 7 years ago

@tyschroed 🎁

tyschroed commented 7 years ago

Bless your heart! On Sun, Oct 22, 2017 at 6:18 PM Jason Pierce notifications@github.com wrote:

@tyschroed https://github.com/tyschroed 🎁

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/2Toad/node-teradata/issues/26#issuecomment-338524652, or mute the thread https://github.com/notifications/unsubscribe-auth/AAweVjLGJP_7-VFxHj6A_T918j-CB4Zkks5su-lIgaJpZM4QBBCz .