mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-11 11:50:54 +08:00
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:
@@ -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;
|
||||
});
|
||||
Reference in New Issue
Block a user