Created
June 5, 2014 04:11
-
-
Save bkerley/8e3d82a142b35ec567be to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fs = require('fs'); | |
var pg = require('pg').native; | |
global.Grailbird = {}; | |
global.Grailbird.data = {}; | |
var tweetFiles = fs.readdirSync("./data/js/tweets"); | |
for (var f in tweetFiles) { | |
eval('global.'+fs.readFileSync('./data/js/tweets/'+ tweetFiles[f])); | |
} | |
pg.connect('postgres://localhost/bonzoesc_tweets', function(err, client, done) { | |
var rollback = function(err, client, done) { | |
console.log("aw fuck"); | |
console.log(err); | |
client.query('ROLLBACK', function(err) { | |
return done(err) | |
}) | |
process.exit(-1) | |
}; | |
client.query('BEGIN', function(err, result) { | |
if(err) return rollback(client); | |
var q = 'INSERT INTO tweets (id_str, text, body) VALUES ($1, $2, $3)'; | |
for (var key in global.Grailbird.data) { | |
var month = global.Grailbird.data[key]; | |
for (var idx in month) { | |
var body = month[idx] | |
client.query(q, [body.id_str, body.text, JSON.stringify(body)], function(err) { | |
if (err) return rollback(err, client, done); | |
}) | |
} | |
} | |
console.log('booya'); | |
client.query('COMMIT', done) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment