postgresql-nxg-cg
v1.0.1
Published
PostGreSQL server client for Node.js
Downloads
4
Readme
Connection
In Node.js library to connect with PosrGreSQL and get the access from the Database Connection.
Installation
Install the module using npm:
npm install pg
npm install postgresql-nxg-cg
# EXAMPLE OF CONNECT TO MSSQL
// Example usage:
const PostgreSQLConnector = require('postgresql-nxg-cg');
// Define PostgreSQL configuration
const pgConfig = {
user: 'your_username',
password: 'your_password',
host: 'your_host',
database: 'your_db',
port: 5432 // PostgreSQL default port
};
// Create an instance of PostgreSQLConnector
const postgresqlConnector = new PostgreSQLConnector(pgConfig);
// Define table name
const tableName = 'Your_table_name'; //
// Define data for INSERT DATA
const insertData = {
column1: 'value1',
column2: 'value2',
column3: 'value3'
};
// Insert data into PostgreSQL
postgresqlConnector.insertData(tableName, insertData)
.then(insertedData => {
console.log('Data inserted successfully:', insertedData);
})
.catch(error => {
console.error('Error inserting data:', error);
});
// Define data for UPDATE operation
const updateData = {
name: 'UpdatedName',
address: 'UpdatedAddress'
};
// Update data in PostgreSQL
postgresqlConnector.updateData(tableName, updateData, { id: 'your_id' })
.then(updatedData => {
console.log('Data updated successfully:', updatedData);
})
.catch(error => {
console.error('Error updating data:', error);
});
// Define condition for DELETE operation
const deleteCondition = { id: 'your_id' };
// Delete data from PostgreSQL
postgresqlConnector.deleteData(tableName, deleteCondition)
.then(deletedData => {
console.log('Data deleted successfully:', deletedData);
})
.catch(error => {
console.error('Error deleting data:', error);
});
// RETRIEVE data from PostgreSQL
postgresqlConnector.retrieveData(tableName)
.then(retrievedData => {
console.log('Retrieved data:', retrievedData);
})
.catch(error => {
console.error('Error retrieving data:', error);
});
this is the example of login with credentials and getting the data from the MSSQL