Created
June 26, 2014 15:46
-
-
Save Igosuki/4e4c7c711547d8048df5 to your computer and use it in GitHub Desktop.
Create piecharts data
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
#!/usr/local/bin/node | |
var pg = require('pg'); | |
var moment = require('moment'); | |
var knex = require('knex')({ | |
client: 'pg', | |
connection: { | |
host: '127.0.0.1', | |
user: 'front', | |
password: 'lol', | |
database: 'dev', | |
charset: 'utf8' | |
} | |
}); | |
var bookshelf = require('bookshelf')(knex); | |
var FundingRequest = bookshelf.Model.extend({ | |
tableName: 'funding_requests' | |
}); | |
var options = {}; | |
process.argv.forEach(function(val, index, array) { | |
if(index > 1) { | |
if(val === '--sequences') { | |
listSequences() | |
} | |
} | |
}); | |
var now = moment(); | |
var baseAmount = 10000; | |
var amountVariationBase = 5000; | |
for(var i = 0; i < 250; i++) { | |
var fakeCreationDate = now.add(moment.duration(i%10, 'days')) | |
insertRecord({ | |
status: "submitted", | |
amount: baseAmount + (amountVariationBase * i % 5) / (i + 1 % 10), | |
created_at: fakeCreationDate.toJSON(), | |
updated_at: fakeCreationDate.toJSON(), | |
seller_id: 2 | |
}); | |
} | |
function listSequences() { | |
client.query("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'", | |
function(err, result) { | |
if(err) { | |
return console.error('Error getting sequence', err) | |
} | |
console.log(result.rows); | |
} | |
) | |
} | |
function insertRecord(fundingRequestObject) { | |
new FundingRequest(fundingRequestObject).save().then(function(model) { | |
console.log(JSON.stringify(model)); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment