Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including q-db with all npm packages installed. Try it out:

var qDb = require("q-db")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

q-db v0.0.1

Promise utilities for Sequelize models


Promise utilities for Sequelize models.


Define a model in sequelize and create a Qdb instance for the model.

var Sequelize = require('sequelize');
var Qdb = require('./qdb');

var sequelize = new Sequelize('somethingsomethingmysql');

var user = sequelize.define('user', {
    id      : { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
    name    : { type: Sequelize.STRING },
    password : { type: Sequelize.STRING }

var quser = new Qdb(sequelize, user);

Then you can use it and it'll return promises for just about anything.

// create a user with the given properties
var promise = quser.create({ name: 'philipp', password: 'notplaintextplease' });

// update password where name = 'philipp'
var promise = quser.update({ password: 'wait' }, { name: 'philipp' });

With everything being properties and promises it gets really when you combine it with a framework like Connect, Express. Especially when you have extra middleware that handles promises:

// Adds the `.promise` method to every response object, so promises can be returned
app.use(function (req, res, next) {
    res.promise = function (promise) {
            .then(function (result) {
                res.json(200, result);
            .fail(function (err) {
                res.json(err.httpcode || 500, err.message);

Assuming you'd want to return all properties of a model, you'd be able to do something like this:

app.get('/api/todo/:id', function (req, res) {
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free