Skip to content

Instantly share code, notes, and snippets.

@volodymyrlut
Created December 24, 2015 08:27
Show Gist options
  • Save volodymyrlut/ee6c403826e5104962c2 to your computer and use it in GitHub Desktop.
Save volodymyrlut/ee6c403826e5104962c2 to your computer and use it in GitHub Desktop.
var db = require('../db').db
db.run("CREATE TABLE IF NOT EXISTS dorns (id INTEGER PRIMARY KEY AUTOINCREMENT, dorn TEXT, facultee TEXT, places INTEGER)");
var newJob = function(data){
db.run("INSERT INTO dorns (dorn, facultee, places) VALUES ('"+ data.company + "', '" + data.job + "', " + data.salary + ")");
}
var allJobs = function(c){
db.all("SELECT rowid AS id, * FROM dorns", function(err, rows) {
c(rows);
});
}
var sortByJob = function(c){
db.all("SELECT dorn, MAX(places) AS avg FROM dorns GROUP BY facultee", function(err, rows) {
c(rows);
});
}
var sortByCompany = function(c){
db.all("SELECT dorn, MAX(places) AS avg FROM dorns GROUP BY facultee", function(err, rows) {
c(rows);
});
}
module.exports.new = newJob;
module.exports.all = allJobs;
module.exports.sortJob = sortByJob;
module.exports.sortCompany = sortByCompany;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment