Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
const airbrake = new Airbrake.Notifier({
projectId: process.env.AIRBRAKE_PROJECT_ID,
projectKey: process.env.AIRBRAKE_PROJECT_KEY,
});
console.log(pg.Client.prototype.query);
const client = new pg.Client();
await client.connect();
const app = express();
// This middleware should be added before any routes are defined.
app.use(airbrakeExpress.makeMiddleware(airbrake));
app.get('/', async function home(req, res) {
const result = await client.query('SELECT $1::text as message', [
'Hello world!',
]);
console.log(result.rows[0].message);
res.send('Hello World!');
});
const loadDDL = async function (filename,startLog, endLog, errorLog) {
const db = JSON.parse(process.env.pgapi);
const client = new Client({
host: db.DB_HOST,
port: db.DB_PORT,
database: db.DB_NAME,
user: db.DB_USER,
password: db.DB_PASSWORD
});
let _startLog = function(filename) {
//console.log("Compiling File : " + filename);
}
let _endLog = function(filename) {
// console.log("File compilation completed : " + filename);
}
let _errorLog = function(filename) {
stream: function(table, options, stream) {
var dbConfig = {
database: dbs[table].config.database,
host: dbs[table].config.host,
user: dbs[table].config.user,
password: dbs[table].config.password,
port: dbs[table].config.port
};
var client = new pg.Client(dbConfig);
client.connect();
// Escape Table Name
table = utils.escapeName(table);
// Build Query
var query = new Query(dbs[table.replace(/["']/g, "")].schema).find(table, options);
// Run Query
var dbStream = client.query(query.query, query.values);
//can stream row results back 1 at a time
dbStream.on('row', function(row) {
stream.write(row);
});
return new Promise((resolve, reject) => {
const client = new pg.Client(pgConfig);
client.connect(err => {
if (err) {
client.end();
return reject(err);
}
const cursor = client.query(new PgCursor(query));
return cursor.read(connection.maxRows + 1, (err, rows) => {
if (err) {
// pg_cursor can't handle multi-statements at the moment
// as a work around we'll retry the query the old way, but we lose the maxRows protection
return client.query(query, (err, result) => {
client.end();
if (err) {
return reject(err);
}
return resolve({ rows: result.rows });
it("should be accept protocol alias", function (done) {
var db = new pg.Client();
ORM.use(db, "pg", function (err) {
should.equal(err, null);
return done();
});
});
exports.handler = async (event) => {
let client = new Client()
await client.connect()
let deleteAccount = `
DELETE FROM transactions
WHERE debitor=$1 OR creditor=$1 or author=$1;`
let deleteOne = await client.query(deleteAccount, [event.accountOne])
let deleteTwo = await client.query(deleteAccount, [event.accountTwo])
let oneMessage = `Row count affected by ${deleteOne.command} command: ${deleteOne.rowCount}`
console.log(oneMessage)
let twoMessage = `Row count affected by ${deleteTwo.command} command: ${deleteTwo.rowCount}`
console.log(twoMessage)
let msg = oneMessage + ', ' + twoMessage
await client.end()
return msg
}
var connectionString = 'postgres://postgres:@localhost:5432/pgipc'
var pg = require('pg')
var ipc = require('.')
var stats = require('statistics')
var speedometer = require('speedometer')
var assert = require('assert')
var client = new pg.Client(connectionString)
client.connect(assert.ifError)
var ee = ipc(client)
ee.once('error', assert.ifError)
ee.once('end', function () {
client.end()
})
var speed = speedometer(10)
if (process.argv[2] === 'SOURCE') {
ee.on('notify', function () {
console.log('Source: ', speed(1))
})
constructor(databaseConfig: DatabaseConfig) {
this.databaseConfig = databaseConfig;
this.client = new Client(this.databaseConfig);
}
async removeFunding(networkId,txHash){
if (!networkId) throw Error("no networkId");
if (!txHash) throw Error("no txHash");
if (!this.pgUrl) throw Error("no pgUrl set");
const client = new Client({
connectionString: this.pgUrl
});
try {
await client.connect();
const res = await client.query(
"DELETE FROM fundings \
WHERE network=$1 \
AND tx_hash=$2",
[networkId,txHash]
);
} catch (e) {
throw e;
} finally {
await client.end();
}
function getMetaInfoByRgPrefix(rgPrefix) {
const pgClient = new pg.Client(pgConfig());
const query = `
select
resource_group_prefix,
application_object_id,
expiration_datetime
from sandbox
where resource_group_prefix = '${rgPrefix}';
`;
pgClient.on('error', pgErrorHandler);
return pgClient.connect()
.then(() => pgClient.query(query))
.then(res => res.rows);
}