Skip to content

Art-Chen/node-openGauss

 
 

Repository files navigation

English | 简体中文

demand

Node-OpenGauss is implemented based on Node-PostGre.Achieve SHA256 encryption connection

node-opengauss

A simple openGauss client for Node.js based on node-postgres.

Install

npm install

Test Case

const { Pool, Client } = require('./lib')


const pgConfig = {
  user: '*********',
  database: 'postgres',
  password: '********',
  host: '************',
  port: 5432,
}
const pool = new Pool(pgConfig)

pool.on('error', (err, result) => {
  return console.error('catch error: ', err)
})

pool.connect((err, client, release) => {
  if (err) {
    return console.log('can not connect to postgresql server.')
  }
  client.query('DROP TABLE test;')
  client.query(`CREATE TABLE test
  (
      c_customer_sk             integer
  );`)
  client.query('insert into test values(1111)', (err, res) => {
    console.log(res)
  })
  client.query('update test set c_customer_sk = 2222', (err, res) => {
    console.log(res)
  })
  client.query('SELECT * FROM test;', (err, res) => {
    console.log(res)
  })
  client.query('delete from test where c_customer_sk = 2222', (err, res) => {
    console.log(res)
  })
  client.query('SELECT * FROM test;', (err, res) => {
    console.log(res)
  })
  release()
  return console.log('connect to postgresql successfully!')
})
function rollback(client) {
  //terminating a client connection will
  //automatically rollback any uncommitted transactions
  //so while it's not technically mandatory to call
  //ROLLBACK it is cleaner and more correct
  return client
    .query('ROLLBACK')
    .then(() => client.end())
    .catch(() => client.end())
}

Development

Development on MacOS/Linux is preferred :)

  1. Please deploy OpenGauss on CentOS 7 or openEuler 20.3 LTS
  2. Ensure you have a openGauss instance running, follow this https://opengauss.org/zh/docs/2.0.1/docs/Quickstart/Quickstart.html to set up it

Run the project

Navigate to examples and run following to test driver:

/*
  example
*/
cd packages/pg/  
node test-1.js

Notes

Posts

  • [SEMMNI ERROR]

    When doing simpleinstall, we may get this error

    "On systemwide basis, the maximum number of SEMMNI is not correct. the current SEMMNI value is: .... Please check it."

    According to the installation script, SEMMNI should be greater than 321.875

    On CentOS 7 we can do this to modify it

    $ sudo vim /etc/sysctl.conf

    Add this line to the end of file

    kernel.sem = 250 32000 100 400

    Then use shift + double z or :wq to save and exit the vim

    Finally execute it to apply our settings

    $ /sbin/sysctl -p 
  • [The account was locked]

    Enter the gsql on your server

    Then run this

    alter user [username] account unlock;

  • [Adding IPv4 rules allows all external links to the password to be verified by SHA256]

    Open this file: /opt/software/openGauss/data/single_node/pg_hba.conf

    add this: host all all 0.0.0.0/0 sha256

  • [GUC]

    Click here

About

A simple openGauss driver for node.js based on node-Postgres

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 80.7%
  • TypeScript 18.0%
  • Other 1.3%