Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 1.17 KB

postgresql.md

File metadata and controls

64 lines (46 loc) · 1.17 KB

Node : postgresql

posqtgresql without pool

const dbConfig = {
  user: 'postgres',
  host: 'localhost',
  database: 'backend_admin',
  password: 'Trustno1',
  port: 5432,
};

const { Client } = require('pg');

const connectToDatabase = async () => {

  const client = new Client(dbConfig);
  try {
    await client.connect();
    console.log(`Connected to PostgreSQL as ${client.user}`);
    const result = await client.query('select name from continent');
    console.log('Heure actuelle depuis la base de données :', JSON.stringify(result.rows));
  } finally {
    await client.end();
  }


};
connectToDatabase();

posqtgresql with pool

const dbConfig = {
  user: 'postgres',
  host: 'localhost',
  database: 'backend_admin',
  password: 'Trustno1',
  port: 5432,
};

const { Pool } = require('pg');

const connectToDatabase = async () => {

  var pool = new Pool(dbConfig);
  var client = await pool.connect()
  try {
    const result = await client.query('select name from continent');
    console.log('Heure actuelle depuis la base de données :', JSON.stringify(result.rows));
  } finally {
    client.release();
  }

};
connectToDatabase();