Coder Social home page Coder Social logo

node-opengauss's Introduction

node-opengauss

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

Install

npm install node-opengauss --save

Usage

import OpenGauss from 'node-opengauss'

const client = new OpenGauss()
const config = {
  host: 'localhost',
  port: 5432,
  username: 'lolimay',
  database: 'postgres',
  password: 'Enmo@123'
}

client.connect(config)
client.query('select current_date', result => {
    console.log(result) // { rows: [ { date: 2021-05-26T16:00:00.000Z } ], affectedRows: 1 }
    return client.disconnect()
})

Development

Development on MacOS/Linux is preferred :)

  1. Clone the repo git clone [email protected]:lolimay/node-opengauss.git
  2. Ensure you have a openGauss instance running, follow this tutorial (Chinese Only/仅中文) to set up a local instance with docker

Run the project

Navigate to examples and run following to test driver:

cd examples
node index.js

For Debugging

For more verbose logs by setting the environment variable DEBUG to true:

DEBUG=true node index.mjs

If you need to modify files inside lib/protocol, please run following commands to take effects:

cd lib/protocol
npm run build:watch

Posts

Check here for more posts.

Notes

License

Copyright (c) 2021-2021 Shiqi Mei ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-opengauss's People

Contributors

shiqimei avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-opengauss's Issues

对于OpenGauss的接口,当建立连接或者执行命令失败,是否直接抛出异常更好,由上层应用去处理异常。

我在使用 client.connect(config) 建立数据库连接时候,其实失败了,但是程序还是继续往下执行。 这种情况是否抛出异常更好,而不是只是去打印出来。

async connect(config) {
        if (this.client) throw new Error('连接已建立')
        if (config.username) config.user = config.username
        if (config.dbname) config.database = config.dbname
        this.client = new this.Client(config)
        // 建立TCP连接
        this.client.connect()
            .then(() => {})
            .catch(err => console.error(err))         ################## 直接抛出异常
        return this.client
    }
    // SQL语句执行功能
    query(sql, callback = () => {}) {
        // const timeStart = Date.now()
        this.client.query(sql, (err, res) => {
            if (err) return console.error(err)                     ################## 直接抛出异常
            const data = res
            if (data) {
                const result = {}
                if (data.rows.length) {
                    result.rows = data.rows
                }
                if (data.rowCount > 0) {
                    result.affectedRows = data.rowCount
                }
                callback(result)
            }
            // 记录 SQL 执行用时
            // console.log(`SQL \`${ sql }\` finished in ${ Date.now() - timeStart }ms`)
        })
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.