0.0.7 • Published 8 years ago

mysql-adapter v0.0.7

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

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 {table, where}, (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 {table, columns, where}, (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 {table1, table2, joinType, columns, joinBy, where}, (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 {table, row, ignore}, (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 {table, row, where}, (err, res) ->
0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago