https://github.com/eternalsayed/es-helper-mysql
DB Helper for NodeJS projects
https://github.com/eternalsayed/es-helper-mysql
dependency es-module mysql nodejs
Last synced: 2 months ago
JSON representation
DB Helper for NodeJS projects
- Host: GitHub
- URL: https://github.com/eternalsayed/es-helper-mysql
- Owner: eternalsayed
- Created: 2019-03-02T08:57:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-16T23:30:08.000Z (almost 3 years ago)
- Last Synced: 2025-03-22T22:16:31.755Z (about 1 year ago)
- Topics: dependency, es-module, mysql, nodejs
- Language: JavaScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# es-helper-mysql
Utility functions wrapper over native NodeJS `mysql` package to perform operations like connect, querying, insertion, batch-insertion, etc. easily. Could be buggy; use at your risk. Has bee helping me though in a number of projects over years.
## Installation
You can install the utility using `npm`, or you can simply download the zip (Click on 'Download zip' button above) and reference the index.js file in your NodeJS code. Please note that this code is not to be used in Front End as not only it is irrelevant, but may fail as well.
Using `npm`, run below command:
`npm i --save https://github.com/eternalsayed/es-helper-mysql`
## Usage
```javascript
const esMysql = require('es-helper-mysql');
const dbo = esMysql.getDbHandle();
const instance = dbo.getInstance();
instance.query('SELECT * FROM users', (err, res) => {
instance.end();//don't keep the resources occupied!
callback(err, res);
});
```
## Helper functions
### connect()
Selects one of the configuration from availables ones, based on the `__mode` set via `setCommonGlobals` in `es-util-app`. Since you can override these values (not advisable though) at any place, you can choose any of the configurations of available DB configs before the connect function is called.
## Contributing:
You're more than welcome to help me improvise this code. To begin, fork the project, create a branch in your name from `master` and when you're done, please raise a `pull-request`. I'll try to be prompt in merging your requests ASAP.