Socket
Socket
Sign inDemoInstall

gost-mysql

Package Overview
Dependencies
16
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gost-mysql

GostMySQL. An upgrade of mysql2. Code updated by gost


Version published
Weekly downloads
11
increased by37.5%
Maintainers
1
Install size
2.41 MB
Created
Weekly downloads
 

Readme

Source

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}

Keywords

FAQs

Last updated on 22 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc