mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-22 03:51:33 +00:00
Update database-integration.md
Syncing with the English version of the document, in regards to integration with PostgreSQL.
This commit is contained in:
@@ -226,12 +226,12 @@ apoc.query('match (n) return n').exec().then(
|
||||
|
||||
## PostgreSQL
|
||||
|
||||
**Módulo**: [pg](https://github.com/brianc/node-postgres)
|
||||
**Módulo**: [pg-promise](https://github.com/vitaly-t/pg-promise)
|
||||
**Instalación**
|
||||
|
||||
<pre>
|
||||
<code class="language-sh" translate="no">
|
||||
$ npm install pg
|
||||
$ npm install pg-promise
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
@@ -239,23 +239,16 @@ $ npm install pg
|
||||
|
||||
<pre>
|
||||
<code class="language-javascript" translate="no">
|
||||
var pg = require('pg');
|
||||
var conString = "postgres://username:password@localhost/database";
|
||||
var pgp = require("pg-promise")(/*options*/);
|
||||
var db = pgp("postgres://username:password@host:port/database");
|
||||
|
||||
pg.connect(conString, function(err, client, done) {
|
||||
|
||||
if (err) {
|
||||
return console.error('error fetching client from pool', err);
|
||||
}
|
||||
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
|
||||
done();
|
||||
if (err) {
|
||||
return console.error('error running query', err);
|
||||
}
|
||||
console.log(result.rows[0].number);
|
||||
});
|
||||
|
||||
});
|
||||
db.one("SELECT $1 AS value", 123)
|
||||
.then(function (data) {
|
||||
console.log("DATA:", data.value);
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log("ERROR:", error);
|
||||
});
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user