Socket
Socket
Sign inDemoInstall

jano-mysql

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jano-mysql

Library that uses the `mysql` driver to keep code clean, simple, organized and with Promises


Version published
Maintainers
1
Created

Readme

Source

jano-mysql

NPM Version NPM Downloads GitHub issues GitHub forks Build Status Twitter

[EN]

It is a library that uses the mysql driver to keep code clean, simple, organized and with Promises.

Requirements

  • Node 8+

Installation

npm install jano-mysql --save

or

yarn add jano-mysql

Examples of use

  • To load the library, put the database settings inside the constructor.
const mysql = require('jano-mysql')({
    host: 'localhost',
    user: 'root',
    database: 'meubanco',
    password: '',
    port: 3306
});
  • Transaction
    Starts an open transaction
let conexao = await mysql.beginTransaction();
  • Execute commands in the transaction
let transacaoA = await mysql.executeTransaction(conexao, "INSERT INTO venda SET ?", { IDPRODUTO: 1, IDCLIENTE: 2 })

let transacaoB = await mysql.executeTransaction(conexao, `UPDATE estoque SET ? WHERE IDESTOQUE = ${IDESTOQUE}`, { VALOR: 2 })
  • Terminates a connection (non-mandatory parameter)
true = commit 
false = rollback
let conexaoEncerrada = await conexao.endConnection(true);
  • Free Query, enter whatever you want, the return will be in .content
let motivos = await mysql.executeString('SELECT * FROM motivo');
console.log(motivos.content);
  • Insert/Update record
let insert = await mysql.executeObject("INSERT INTO motivo SET ?", { DESCRICAO: 'teste' });
console.log(insert);
  • Return records from a procedure
let procedure = await mysql.readProcedure("SP_MOTIVO", [1]);
console.log(procedure);

[PT-BR]

É uma biblioteca que utiliza o driver do mysql mantendo um código mais limpo, simples, organizado com Promises.

Requisitos

Instalação

npm install jano-mysql --save

ou

yarn add jano-mysql

Exemplos de uso

  • Para carregar a biblioteca
    coloque no construtor as configurações do banco de dados.
const mysql = require('jano-mysql')({
    host: 'localhost',
    user: 'root',
    database: 'meubanco',
    password: '',
    port: 3306
});
  • Transação
    Inicia uma conexão aberta com transaction
let conexao = await mysql.beginTransaction();
  • Execute comandos na transação
let transacaoA = await mysql.executeTransaction(conexao, "INSERT INTO venda SET ?", { IDPRODUTO: 1, IDCLIENTE: 2 })

let transacaoB = await mysql.executeTransaction(conexao, `UPDATE estoque SET ? WHERE IDESTOQUE = ${IDESTOQUE}`, { VALOR: 2 })
  • Encerra uma conexão (paramêtro não obrigatório)
true = commit 
false = rollback
let conexaoEncerrada = await conexao.endConnection(true);
  • Query livre, digite o que quiser, o retorno ficará em .content
let motivos = await mysql.executeString('SELECT * FROM motivo');
console.log(motivos.content);
  • Inserir/Atualizar registro
let insert = await mysql.executeObject("INSERT INTO motivo SET ?", { DESCRICAO: 'teste' });
console.log(insert);
  • Retornar registros de uma procedure
let procedure = await mysql.readProcedure("SP_MOTIVO", [1]);
console.log(procedure);

Keywords

FAQs

Last updated on 29 Jul 2017

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