New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mysql-on-the-rocks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-on-the-rocks

A dead-simple MySQL module for Node.js

  • 0.4.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

MySQL On The Rocks alt text Build Status

A dead-simple Node.js module designed for handling storage / retrieval of Javascript objects to MySQL.

The underlying layer uses Q for Promises and node-mysql as adapter.

Quick example

"use strict";


var mysql = require("mysql-on-the-rocks");


// First you need to create a connection to the db
mysql.create({
  host: "localhost",
  port: 3306,
  user: "admin", 
  password: "abcdefgh"
}).then(function (db) {

  // Retrieve an object
  return db.findObject("wallets", { 
    id: 123 
  }).then(function (obj) {

    // Update it
    obj.dollars += 100;
    
    // Save to the db
    return db.save(obj);
  });

}).fail(function (error) {
  // ...
}).done();

API Reference

mysql.findObjects(tableName, query, [order, count, offset])

Finds an object in the database.

ArgumentTypeDescription
tableNameStringName of the table to query on
queryObjectAn object describing the query
orderObjectAn object with fields as keys and order direction as values.
countNumberThe max amount of objects to return
offsetNumberThe starting offset of the result set

Returns Promise<Object>


mysql.findObject(tableName, query, [order, offset])

Alias of mysql.findObjects with count set at 1.


mysql.save(tableName, obj)
ArgumentTypeDescription
tableNameStringName of the table to query on
objObjectThe object to save

Returns Promise<Object>

If the object has an id already, it will be updated, otherwise it will be inserted and the id will be appended.


mysql.insertObject(tableName, obj)

and

mysql.updateObject(tableName, obj)

See mysql.save()


mysql.deleteObject(tableName, object)
ArgumentTypeDescription
tableNameStringName of the table to query on
objObjectThe object to delete (id must be defined)

Returns Promise<Object>

Deletes the object from the table.


mysql.findObjectsWithQuery(queryString)
ArgumentTypeDescription
queryStringStringThe MySQL query

Returns Promise<Object>

Use this method if you want to retrieve objects and not use the internal query builder.


mysql.query(queryString)
ArgumentTypeDescription
queryStringStringThe MySQL query

Returns Promise<Object>

You probably won't use this method that much, but it allows you to call manually the internal query() method of the MySQL driver.

Examples

Save and update an object
mysql.save("users", {
  email: "hello@olivierkaisin.co"
}).then(function (user) {
  // .. user.id is now defined!
  
  // Let's update the email now
  user.email = "hi@olivierkaisin.co";
  return mysql.save("users", user);
}).fail(function (error) {
  // ...
}).done();
Retrieve a set of objects
var tableName = "users";

var query = { 
  planCode: "pro"
};

var order = {
  created: "desc"
};


mysql.findObjects(
  tableName, query, order, 100
).then(function (users) {
  // .. do something with the received users  
}).fail(function (error) {
  // .. handle the error
}).done();

License

MIT

FAQs

Package last updated on 19 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc