1.1.0 • Published 7 years ago

mysql-create-helper v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

mysql-create-helper

A simple cli that creates a file for connecting and querying to your mysql database.

Table of Contents

Install

To install, just enter npm install -g mysql-create-helper

Usage

  1. Go to the directory where you want create the file by entering cd /path/to/create
  2. Enter mysql-generate <filename> <database>

By default, the variables inside the created file are:

  • host = localhost
  • user = root
  • password = ''

You can either manually change these or use the options below:

OptionsUsage
-h, --host [host]Specify host
-u, --user [user]Specify user
-p, --password [password]Specify password

Helper usage

const app = require('express')()
const db = require('./path/to/file')

// Simple SELECT statement
app.get('/', (req, res) => {
  db.query({
    sql: 'SELECT * FROM table',
    chain: data => { // This will allow you to do something after the query
      return res.json(data)
    }
  })
})

app.post('/example-route', (req, res) => {
  db.query({
    sql: 'INSERT INTO table (name, contact) VALUES (?, ?)',
    options: ['Elly', 'elly@gmail.com'], // Binds these parameters to the query
    msg: '/example-route' // A custom message after the query. If not specified, it will log the sql and tells if it's an error or success
  })
})
1.1.0

7 years ago

1.0.0

7 years ago