mysql-adapter

0.0.7 • Public • Published

MySQL Adapter

Build Status

mysql-adapter is a package with helper functions to be used when working on javascript apps which use mysql.

Examples

# Require the package 
{MySQL} = require 'mysql-adapter'
 
# Make your mysql config 
config = 
  host: 'localhost'
  password: ''
  database: 'database'
  
# Make new instance of MySQL 
conn = new MySQL config
 
# Connect 
conn.connect (err) ->
  # Do stuff 
# Making a custom query 
conn.query 'SELECT * from table'(err, res) ->
# Select all columns in a table without where clause 
# SELECT * FROM `table` 
table = 'table'
conn.selectAll {table}(err, res) ->
 
# Select all columns in a table with where clause 
# SELECT * FROM `table` WHERE `id` = 1 
where = id: 1
conn.selectAll {tablewhere}(err, res) ->
# Select specific columns in a table 
# SELECT `id`, `first_name` FROM `table` WHERE `id` = 1 
table = 'table'
columns = ['id''first_name']
where = id: 1
conn.select {tablecolumnswhere}(err, res) ->
# Query with join 
###
  SELECT * FROM `users`
  RIGHT JOIN `pictures` on users.id = pictures.picture_id
  where pictures.id = 1
###
table1 = 'users'
table2 = 'pictures'
joinType = 'RIGHT'
columns = ['id''first_name']
joinBy = 
  'id': 'picture_id'
where = id: 1
conn.join {table1table2joinTypecolumnsjoinBywhere}(err, res) ->
# Insert a row 
# INSERT IGNORE INTO `users` (`first_name`, `last_name`, `email`) VALUES ('first', 'last', 'email') 
table = 'users'
row = 
  first_name: 'first'
  last_name: 'last'
  email: 'email'
ignore = true
conn.insertOne {tablerowignore}(err, res) ->
# Update a row 
###
 UPDATE `users`
 SET `first_name`='new_first_name' && `last_name`='new_last_name' && `email`='new_email'
 WHERE `id` = 1
###
table = 'users'
row =
  first_name: 'new_first_name'
  last_name: 'new_last_name'
  email: 'new_email'
where = id: 1
conn.insertOne {tablerowwhere}(err, res) ->

Readme

Keywords

Package Sidebar

Install

npm i mysql-adapter

Weekly Downloads

2

Version

0.0.7

License

MIT

Last publish

Collaborators

  • d_andreev