Created
July 25, 2017 18:19
-
-
Save ferm10n/1b8d2cd3a03bf1a8f526d3dadcf1c4a0 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
// I just transformed this shitstain which doesn't property propagate errors from doQuery... | |
insert (site, ...rows) { | |
return new Promise((resolve, reject) => { | |
for (let rowObject of rows) { this.checkIntegrity(rowObject) } | |
let q = sqlQuery.insert().into(this.fromTable).setFieldsRows(rows) | |
return this.doQuery(site, q).then(() => { | |
// return inserted row(s) | |
if (rows.length === 1) { resolve(rows[0]) } else { resolve(rows) } | |
}) | |
}) | |
} | |
// into this gem! (errors propagated properly) | |
async insert (site, ...rows) { | |
for (let rowObject of rows) { this.checkIntegrity(rowObject) } | |
let q = sqlQuery.insert().into(this.fromTable).setFieldsRows(rows) | |
await this.doQuery(site, q) | |
if (rows.length === 1) return rows[0] | |
else return rows | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment