Created
December 24, 2015 08:27
-
-
Save volodymyrlut/ee6c403826e5104962c2 to your computer and use it in GitHub Desktop.
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 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