This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/', function(req, res, next) { | |
models.Blog.findAll({ | |
where: { | |
published: true | |
}, | |
limit: 3, | |
order: [["createdAt","DESC"]], | |
include: [ | |
{ model: models.Photo } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sequelize.getConnection(function (connection) { | |
// do stuff | |
return new Promise(); // connection automatically released back to pool when promise returned from callback is resolved or rejected | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var User = sequelize.define('User') | |
, Task = sequelize.define('Task'); | |
User.Tasks = User.hasMany(Task); | |
Task.User = Task.belongsTo(User); | |
/* | |
* Creation | |
*/ | |
User.create({ /* user values */ }).then(function (user) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indexes: [ | |
{ | |
using: 'GIN', | |
fields: ['field'] | |
} | |
] | |
// CREATE INDEX field ON $modelTable USING gin (field); | |
indexes: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
field: { | |
propa: 'valuea', | |
propb: { | |
propc: 'valueb' | |
} | |
} | |
} | |
// "field"#>>'{propa}' = 'valuea' AND "field"#>>'{propb, propc}' = 'valueb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var deviceToSave = Device.build({}); | |
Device.findOrCreate({ | |
where: {device_id: deviceToSave.device_id}, | |
defaults: deviceToSave.get() | |
}).spread(function(device, created) { | |
if (created) return device; | |
return device.updateAttributes(deviceToSave.get()); | |
}).then(function (item) { | |
response.code(201).send(item.get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'); | |
Promise.reduce(queries, function (results, query) { | |
return sequelize.query(query, null, {raw: true, plain: true}).then(function (result) { | |
return results.concat([result]); | |
}); | |
}, []).then(function (results) { | |
console.log("results"); | |
}).catch(function (err) { | |
console.error("Error": err); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT "Comics".*, | |
"Favourites"."id" AS "Favourites.id", | |
"Favourites"."createdAt" AS "Favourites.createdAt", | |
"Favourites"."updatedAt" AS "Favourites.updatedAt", | |
"Favourites"."UserId" AS "Favourites.UserId", | |
"Favourites"."ComicId" AS "Favourites.ComicId" | |
FROM ( | |
SELECT "Comics".* FROM "Comics" ORDER BY "number" DESC LIMIT 60 | |
) AS "Comics" | |
LEFT OUTER JOIN "Favourites" AS "Favourites" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.7.1 | |
(function() { | |
var AREAS, DAMAGE_MAX, Employee, Location, Report, Sequelize, arg, async, sequelize, start; | |
Sequelize = require('./index'); | |
async = require('async'); | |
AREAS = ['area1', 'area2', 'area3']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'), | |
DAO = require('sequelize/lib/dao'), | |
_increment = DAO.prototype.increment, | |
_decrement = DAO.prototype.decrement; | |
DAO.prototype.increment = function(field, options) { | |
var instance = this, | |
by = (options && options.by) || options || 1; | |
instance.set(field, instance.get(field) + by); |
NewerOlder