Created
November 16, 2015 01:16
-
-
Save itsjoekent/3c710f4fe9fff83b7279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Save a student record to database | |
# string firstName | |
# string lastName | |
# array grades | |
# assignment => grade | |
function addRecord (firstName, lastName, grades) | |
id = random() # Names are not unique and our database could contain conflicting records | |
db_save(id, firstName, lastName, grades) | |
# Find a student record, only one parameter required to perform DB query | |
# int id | |
# string firstName | |
# string lastName | |
function findRecord(id, firstName, lastName) | |
record = db_query | |
where record.id == id | |
where record.firstName == firstName | |
where record.lastName == lastName | |
findOne() | |
return record | |
# Delete a record from the database | |
# int id | |
function deleteRecord(id) | |
db_delete(id) | |
# Update the grades for a record | |
# int id | |
# array grades | |
# assignment => grade | |
function updateGrades(id, grades) | |
record = findRecord(id) | |
record.grades = concat(record.grades, grades) | |
db_update(id, record) | |
# Prints the record of the specified ID | |
# int id | |
function printRecord(id) | |
record = findRecord(id) | |
print record.lastName + ", " + record.firstName | |
foreach record.grades as grade | |
print grade.name + ": " + grade.value | |
# Prints all records in the database | |
function printAllRecords() | |
ids = db_query | |
select id | |
from records | |
find() | |
foreach ids as id | |
printRecord(id) | |
function main() | |
db_connect() | |
print "Welcome, please type a command" | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment