Created
December 24, 2015 08:27
-
-
Save volodymyrlut/15a9db368f41731b6544 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 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