ma

mysql-adapter

MySQL Adapter

Showing:

Popularity

Downloads/wk

1

GitHub Stars

0

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

3

Size (min+gzip)

115.1KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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) ->

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100