Created
July 2, 2015 18:54
-
-
Save MrArnoldPalmer/c502d575b87235472553 to your computer and use it in GitHub Desktop.
save example trade to current round db
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 pg = require('pg'); | |
var connectionString = process.env.DATABASE_URL || 'postgres://mitchellvaline:postgres@localhost:5432/csrest'; | |
var playerSchema = { | |
"steamid": "76561198065546545", | |
"communityvisibilitystate": 3, | |
"profilestate": 1, | |
"personaname": "Barry Gibb's Chest Hair", | |
"lastlogoff": 1435695948, | |
"commentpermission": 1, | |
"profileurl": "http://steamcommunity.com/profiles/76561198065546545/", | |
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/40ada71d3b853c45c160b69f7d5a2a70d5c70abe.jpg", | |
"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/40ada71d3b853c45c160b69f7d5a2a70d5c70abe_medium.jpg", | |
"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/40ada71d3b853c45c160b69f7d5a2a70d5c70abe_full.jpg", | |
"personastate": 1, | |
"realname": "Jason", | |
"primaryclanid": "103582791437779840", | |
"timecreated": 1340079207, | |
"personastateflags": 0, | |
"loccountrycode": "US", | |
"items": [ | |
{ | |
"appid": 730, | |
"contextid": 2, | |
"classid": "310776584", | |
"instanceid": "0", | |
"icon_url": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgposbupIgthwczAaAJU7c6_l4GGmMj5Nr_Yg2YfvZZy2rnDptWs3gDg-xA_NT-hJoOcd1U3aViB_QO_l-ntjZe7tJ7MnGwj5HdA_uNfzg", | |
"name": "Galil AR | VariCamo", | |
"market_hash_name": "Galil AR | VariCamo (Field-Tested)", | |
"median_price": "$0.04" | |
} | |
] | |
}; | |
function UpdateRoundPlayers() { | |
var players = []; | |
pg.connect(connectionString, function(err, client, done) { | |
var query = client.query("SELECT players FROM rounds ORDER BY game_id DESC LIMIT 1"); | |
query.on('row', function(row) { | |
players.push(row.players); | |
}); | |
query.on('end', function() { | |
var updated = []; | |
if(players[0] === null) { | |
updated = [playerSchema]; | |
} | |
else { | |
updated = players[0].concat(playerSchema); | |
} | |
console.log(updated); | |
var x = []; | |
pg.connect(connectionString, function(err, client, done) { | |
client.query("UPDATE rounds SET players=($1) WHERE game_id=(SELECT MAX(game_id) FROM rounds)", [JSON.stringify(updated)]); | |
var query = client.query("SELECT players FROM rounds ORDER BY game_id DESC LIMIT 1"); | |
query.on('row', function(row) { | |
x.push(row); | |
}); | |
query.on('end', function() { | |
client.end(); | |
console.log(x); | |
}); | |
if (err) { | |
console.log(err); | |
} | |
}); | |
}); | |
if (err) { | |
console.log(err); | |
} | |
}); | |
} | |
UpdateRoundPlayers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment