UNPKG

@gdksoftware/mysql

Version:
53 lines (40 loc) 1.4 kB
# @gdksoftware/mysql This is a wrapper for the [mysql](https://www.npmjs.com/package/mysql) package. It makes it easier to connect and execute queries. It supports both common Javascript and TypeScript as well. One of the advantages is that you don't have to think about ending the connection with the database. The query command will do this automatically for you. ## Installation ```sh npm install @gdksoftware/mysql yarn add @gdksoftware/mysql bower install @gdksoftware/mysql --save ``` ## Usage ### Javascript ```javascript const MySQL = require('@gdksoftware/mysql'); let db = new MySQL({ host: 'localhost', user: 'root', password: 'pwd', port: '3306', database: 'mydb' }) // Query without parameters db.query('SELECT * FROM user').then((rows) => { // Do something with the given rows }, (err) => { // Handle the exception }) ``` ### TypeScript The import differs For TypeScript, but you can use it like the common Javascript example. ```typescript import MySQL from '@gdksoftware/mysql'; // Query with parameters let userid = 100 db.query('SELECT * FROM user WHERE id = ?', [userid]).then((rows) => { // Do something with the given rows }, (err) => { // Handle the exception }) ``` Package built by [GDK Software NL]('http://www.gdksoftware.nl) / [GDK Software UK]('http://www.gdksoftware.co.uk)