Last active
August 29, 2015 13:59
-
-
Save wlaurance/10780836 to your computer and use it in GitHub Desktop.
tempus db transaction consumer
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
deleteOne: (key, callback)-> | |
{time_entry} = TimeEntriesController | |
deleteProjectTimeEntries = time_entry.delete().where(time_entry.projectId.equals(key)) | |
deleteProject = @project.delete().where(@project.id.equals(key)) | |
deleteUsersProjectsRows = @usersprojects.delete().where(@usersprojects.projectId.equals key) | |
t = @transaction() | |
start = -> | |
async.eachSeries [deleteProjectTimeEntries, deleteUsersProjectsRows, deleteProject], | |
(s, cb)-> | |
t.query s, (err)-> | |
cb(err) | |
, -> | |
t.commit() | |
t.on 'begin', start | |
t.on 'error', callback | |
t.on 'commit', -> | |
callback() | |
t.on 'rollback', -> | |
callback new Error "Could not delete project with id #{key}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment