Skip to content

Commit

Permalink
Ensure transaction finishes before returning results (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
iancamp authored Dec 16, 2022
1 parent b51e933 commit 5d60a6c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ const Adapter = {
create (connectionName, tableName, record, cb) {
let cxn = this.connections.get(connectionName)
let pk = this.getPrimaryKey(cxn, tableName)
let newRecord;

return cxn.knex.transaction(txn => {
return txn.insert(Util.castRecord(record))
Expand All @@ -265,11 +266,13 @@ const Adapter = {
return txn.select().from(tableName).where('rowid', rowid)
})
.then(([ created ]) => {
let record = Util.castSqlValues(created, cxn.collections[tableName])
_.isFunction(cb) && cb(null, record)
return record
newRecord = Util.castSqlValues(created, cxn.collections[tableName])
return newRecord
})
.catch(AdapterError.wrap(cb))
}).then(() => {
_.isFunction(cb) && cb(null, newRecord)
return newRecord;
})
},

Expand Down

0 comments on commit 5d60a6c

Please sign in to comment.