gost-mysql
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

gost-mysql

A small update of mysql2 with json query log backup. It helps us to take backup log of query executed in node. Module only create log for Insert, Update, Delete queries only.

Installation

Create a public folder in the root if you does not have in your project.

MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues.

npm install --save gost-mysql

Using Promise Wrapper

MySQL2 also support Promise API. Which works very well with ES7 async await.

async function main() {
  // get the client
  const mysql = require('mysql2/promise');
  // create the connection
  const connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test'});
  // query database
  const [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14], 'by whom');
}

Array Results

If you have two columns with the same name, you might want to get results as an array rather than an object to prevent them from clashing. This is a deviation from the [Node MySQL][node-mysql] library.

For example: select 1 as foo, 2 as foo.

You can enable this setting at either the connection level (applies to all queries), or at the query level (applies only to that specific query).

Connection Level

const con = mysql.createConnection(
  { host: 'localhost', database: 'test', user: 'root', rowsAsArray: true }
);

Query Level

con.query({ sql: 'select 1 as foo, 2 as foo', rowsAsArray: true }, function(err, results, fields) {
  console.log(results); // in this query, results will be an array of arrays rather than an array of objects
  console.log(fields); // fields are unchanged
});

--You can get the json file in your public/gost/mysql folder path--

--Code updated by godofsoftwaret@gmail.com-MK-3794-{P}

Package Sidebar

Install

npm i gost-mysql

Weekly Downloads

6

Version

1.1.0

License

MIT

Unpacked Size

606 kB

Total Files

107

Last publish

Collaborators

  • gost1