Adding type definitions for pg

This is heavily based on the definitions from sqlite3. The Connection
class is not defined because pg says that it is private for most use
cases. I left that work for people who need it.
This commit is contained in:
Phips Peter
2014-05-30 12:34:46 -07:00
parent af346df404
commit 8fb6309e8d
2 changed files with 124 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
/// <reference path="pg.d.ts" />
import pg = require("pg");
var conString = "postgres://username:password@localhost/database";
// Client pooling
pg.connect(conString, (err, client, done) => {
if (err) {
return console.error("Error fetching client from pool", err);
}
client.query("SELECT $1::int AS number", ["1"], (err, result) => {
done();
if (err) {
return console.error("Error running query", err);
}
console.log(result.rows[0]["number"]);
return null;
});
return null;
});
// Simple
var client = new pg.Client(conString);
client.connect((err) => {
if (err) {
return console.error("Could not connect to postgres", err);
}
client.query("SELECT NOW() AS 'theTime'", (err, result) => {
if (err) {
return console.error("Error running query", err);
}
console.log(result.rows[0]["theTime"]);
client.end();
return null;
});
return null;
});