Skip to content

Instantly share code, notes, and snippets.

@mxmzb
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save mxmzb/60f518f72aaf2d800a62 to your computer and use it in GitHub Desktop.

Select an option

Save mxmzb/60f518f72aaf2d800a62 to your computer and use it in GitHub Desktop.
Bookshelf fetchAll()
var _ = require("underscore"),
steam = require("steam"),
util = require("util"),
fs = require("fs"),
dota2 = require("dota2"),
bot = new steam.SteamClient(),
Dota2 = new dota2.Dota2Client(bot, true);
var models = require("./models");
new models.User().query({ where: { bot_status: 'pending' }}).fetchAll().then(function(users){
console.log(JSON.stringify(users));
console.log(users.toJSON());
_.each(users, function(user){
console.log(user.toJSON());
if(bot.friends[user.steam_id] == 2) {
user.set({ bot_status: 'accepted' });
console.log(user.steam_id+" was added as a friend.");
// knex.select('friends_count').from('bots').where({ steam_id: bot.steamID }).limit(1).then(function(rows){
// knex('bots').where({ steam_id: bot.steamID }).update({ friends_count: (rows[0].friends_count + 1) });
// console.log("Bot " + config.steam_name + " has now " + (rows[0].friends_count + 1) + " friends.");
// });
}
})
});
// output for users:
{ model:
{ [Function]
super_: { [Function] extend: [Function] },
NotFoundError: [Function: ErrorCtor],
collection: [Function],
forge: [Function],
where: [Function],
query: [Function],
fetchAll: [Function],
extend: [Function],
__super__:
{ _builder: [Function],
Collection: [Object],
_relation: [Function] } },
length: 2,
models:
[ { attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c2',
id: 2,
_events: [Object] },
{ attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c3',
id: 3,
_events: [Object] } ],
_byId:
{ '2':
{ attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c2',
id: 2,
_events: [Object] },
'3':
{ attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c3',
id: 3,
_events: [Object] },
c2:
{ attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c2',
id: 2,
_events: [Object] },
c3:
{ attributes: [Object],
_previousAttributes: [Object],
changed: {},
relations: {},
cid: 'c3',
id: 3,
_events: [Object] } },
_knex: null,
_events: { fetching: [ [Object] ], fetched: [ [Object] ] } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment