How to use the machinepack-postgresql.sendNativeQuery function in machinepack-postgresql

To help you get started, we’ve selected a few machinepack-postgresql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balderdashy / sails-postgresql / helpers / private / query / run-query.js View on Github external
throw new Error('Invalid options argument. Options must contain: connection, nativeQuery, and leased.');
  }

  if (!_.has(options, 'connection') || !_.isObject(options.connection)) {
    throw new Error('Invalid option used in options argument. Missing or invalid connection.');
  }

  if (!_.has(options, 'nativeQuery')) {
    throw new Error('Invalid option used in options argument. Missing or invalid nativeQuery.');
  }


  //  ╦═╗╦ ╦╔╗╔  ┌┐┌┌─┐┌┬┐┬┬  ┬┌─┐  ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬
  //  ╠╦╝║ ║║║║  │││├─┤ │ │└┐┌┘├┤   │─┼┐│ │├┤ ├┬┘└┬┘
  //  ╩╚═╚═╝╝╚╝  ┘└┘┴ ┴ ┴ ┴ └┘ └─┘  └─┘└└─┘└─┘┴└─ ┴
  PG.sendNativeQuery({
    connection: options.connection,
    nativeQuery: options.nativeQuery,
    valuesToEscape: options.valuesToEscape,
  })
  .switch({
    // If there was an error, check if the connection should be
    // released back into the pool automatically.
    error: function error(err) {
      if (!options.disconnectOnError) {
        return cb(err);
      }

      releaseConnection(options.connection, options.leased, function releaseConnectionCb(err) {
        return cb(err);
      });
    },
github balderdashy / sails-postgresql / helpers / private / query / run-native-query.js View on Github external
module.exports = function runNativeQuery(connection, query, valuesToEscape, cb) {
  PG.sendNativeQuery({
    connection: connection,
    nativeQuery: query,
    valuesToEscape: valuesToEscape,
  })
  .switch({
    error: function error(err) {
      return cb(err);
    },

    // If the query failed, try and parse it into a normalized format.
    queryFailed: function queryFailed(report) {
      // Parse the native query error into a normalized format
      var parsedError;
      try {
        parsedError = PG.parseNativeQueryError({
          nativeQueryError: report.error
github balderdashy / sails-postgresql / test / support / bootstrap.js View on Github external
}).exec(function getConnectionCb(err, report) {
    if (err) {
      return cb(err);
    }

    var query = [
      'INSERT INTO "' + tableName + '" ("fieldA", "fieldB", "fieldC", "fieldD") ',
      'values (\'foo\', \'bar\', null, null), (\'foo_2\', \'bAr_2\', $1, $2);'
    ].join('');

    PG.sendNativeQuery({
      connection: report.connection,
      nativeQuery: query,
      valuesToEscape: [new Buffer([1, 2, 3]), new Date('2001-06-15 12:00:00')]
    }).exec(function seedCb(err) {
      if (err) {
        return cb(err);
      }

      PG.releaseConnection({
        connection: report.connection
      }).exec(cb);
    });
  });
};