MySQL Adapter
mysql-adapter
is a package with helper functions to be used when working on javascript apps which use mysql.
Examples
# Require the package require 'mysql-adapter' # Make your mysql config config = host: 'localhost' password: '' database: 'database' # Make new instance of MySQL conn = config # Connect connconnect # Do stuff
# Making a custom query connquery 'SELECT * from table'
# Select all columns in a table without where clause # SELECT * FROM `table` table = 'table'connselectAll table # Select all columns in a table with where clause # SELECT * FROM `table` WHERE `id` = 1 where = id: 1connselectAll tablewhere
# Select specific columns in a table # SELECT `id`, `first_name` FROM `table` WHERE `id` = 1 table = 'table'columns = 'id''first_name'where = id: 1connselect tablecolumnswhere
# 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: 1connjoin table1table2joinTypecolumnsjoinBywhere
# 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 = trueconninsertOne tablerowignore
# 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: 1conninsertOne tablerowwhere