Skip to content

Instantly share code, notes, and snippets.

@volodymyrlut
Created December 24, 2015 08:27
Show Gist options
  • Save volodymyrlut/15a9db368f41731b6544 to your computer and use it in GitHub Desktop.
Save volodymyrlut/15a9db368f41731b6544 to your computer and use it in GitHub Desktop.
var db = require('../db').db
db.run("CREATE TABLE IF NOT EXISTS students (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, super_student TEXT, facultee TEXT)");
var newStudent = function(data){
db.run("INSERT INTO students (name, super_student, facultee) VALUES ('"+ data.name + "', '" + data.super_student + "', '" + data.facultee + "')");
}
var allStudents = function(c){
db.all("SELECT rowid AS id, * FROM students", function(err, rows) {
c(rows);
});
}
var superStudents = function(c){
db.all("SELECT * FROM students GROUP BY name ORDER BY facultee, super_student", function(err, rows) {
c(rows);
});
}
module.exports.new = newStudent;
module.exports.all = allStudents;
module.exports.sort = allStudents;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment