Skip to content
Thiago Delgado Pinto edited this page Dec 13, 2017 · 3 revisions

A Connection provides a single connection to a database source. It provides the ability to interact with a database through a common set of commands.

var connection = new Connection("postgres://user:password@host/database");
var statement = connection.prepareStatement("SELECT username FROM users WHERE username = ? and password = crypt(?, password)");
statement.query(username, password).then((rows) => {
    if (rows.length == 1) {
        console.log('Logged in as ', username);
    } else {
        console.log('Invalid user');
    }
}).catch((error) => {
    console.log(error);
});
var pool = new StaticPool("postgres://user:password@host/database");
var connection = pool.getConnection();
var statement = connection.prepareStatement("SELECT username FROM users WHERE username = ? and password = crypt(?, password)");
statement.query(username, password).then((rows) => {
    if (rows.length == 1) {
        console.log('Logged in as ', username);
    } else {
        console.log('Invalid user');
    }
    connection.close(); // the connection is released back to the pool
}).catch((error) => {
    console.log(error);
    connection.close(); // the connection is released back to the pool
});
var pool = new DynamicPool("postgres://user:password@host/database");
var connection = pool.getConnection();
var statement = connection.prepareStatement("SELECT username FROM users WHERE username = ? and password = crypt(?, password)");
statement.query(username, password).then((rows) => {
    if (rows.length == 1) {
        console.log('Logged in as ', username);
    } else {
        console.log('Invalid user');
    }
    connection.close(); // the connection is released back to the pool
}).catch((error) => {
    console.log(error);
    connection.close(); // the connection is released back to the pool
});