{"size": 1469, "ext": "js", "max_stars_repo_path": "examples/transaction.js", "max_stars_repo_name": "yahonda/pg-promise", "max_stars_repo_stars_event_min_datetime": "2015-03-10T00:36:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T07:32:33.000Z", "max_issues_repo_path": "examples/transaction.js", "max_issues_repo_name": "yahonda/pg-promise", "max_issues_repo_issues_event_min_datetime": "2015-03-05T15:42:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T03:38:11.000Z", "max_forks_repo_path": "examples/transaction.js", "max_forks_repo_name": "yahonda/pg-promise", "max_forks_repo_forks_event_min_datetime": "2015-03-11T14:02:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T14:18:06.000Z"}
{"max_stars_count": 3367, "max_issues_count": 766, "max_forks_count": 297, "avg_line_length": 32.6444444444, "max_line_length": 88, "alphanum_fraction": 0.6099387338}
/* eslint-disable */

///////////////////////////////////////////////
// This is to show a complete test application;
///////////////////////////////////////////////

const promise = require('bluebird'); // or any other Promise/A+ compatible library;

const initOptions = {
    promiseLib: promise // overriding the default (ES6 Promise);
};

const pgp = require('pg-promise')(initOptions);
// See also: http://vitaly-t.github.io/pg-promise/module-pg-promise.html

// Database connection details;
const cn = {
    host: 'localhost', // 'localhost' is the default;
    port: 5432, // 5432 is the default;
    database: 'myDatabase',
    user: 'myUser',
    password: 'myPassword',

    // to auto-exit on idle, without having to shut-down the pool;
    // see https://github.com/vitaly-t/pg-promise#library-de-initialization
    allowExitOnIdle: true
};
// You can check for all default values in:
// https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js

const db = pgp(cn); // database instance;

db.tx(async t => {
    const user = await t.one('INSERT INTO users(name) VALUES($1) RETURNING id', 'John');
    const event = await t.one('INSERT INTO events(code) VALUES($1) RETURNING id', 123);
    return {user, event};
})
    .then(({user, event}) => {
        // print new user id + new event id;
        console.log('DATA:', user.id, event.id);
    })
    .catch(error => {
        console.log('ERROR:', error); // print the error;
    });
