@evs-chris/ts-pg-dao
Advanced tools
Comparing version 0.7.1 to 0.7.2
{ | ||
"name": "@evs-chris/ts-pg-dao", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"main": "runtime/main.js", | ||
@@ -5,0 +5,0 @@ "typings": "runtime/main.d.ts", |
@@ -230,3 +230,3 @@ "use strict"; | ||
const params = [${model.fields.filter(f => f.pkey || f.optlock).map(f => `model.${f.name}`).join(', ')}]; | ||
const res = await con.query(\`delete from "${model.table}" where ${model.fields.filter(f => f.pkey || f.optlock).map((f, i) => `${f.optlock ? `date_trunc('millisecond', "${f.name}")` : `"${f.name}"`} = $${i + 1}`).join(' AND ')}\`, params); | ||
const res = await con.query(\`delete from "${model.table}" where ${model.fields.filter(f => f.pkey || f.optlock).map((f, i) => `${f.optlock ? `$\{params[${i}] == null ? \`"${f.name}" is null\` : \`date_trunc('millisecond', "${f.name}")\`}` : `"${f.name}"`} = $${i + 1}`).join(' AND ')}\`, params); | ||
if (res.rowCount < 1) throw new Error('No matching row to delete for ${model.name}'); | ||
@@ -240,2 +240,9 @@ if (res.rowCount > 1) throw new Error('Too many matching rows deleted for ${model.name}'); | ||
} | ||
static async deleteById(con: dao.Connection, ${model.pkeys.map(k => `${k.alias || k.name}: ${k.retype || k.type}`).join(', ')}): Promise<boolean> { | ||
const params = [${model.pkeys.map(k => k.alias || k.name).join(', ')}]; | ||
const res = await con.query(\`delete from "${model.table}" where ${model.pkeys.map((k, i) => `"${k.name}" = $${i + 1}`).join(' AND ')}\`, params); | ||
if (res.rowCount !== 1) return false; | ||
return true; | ||
} | ||
@@ -242,0 +249,0 @@ ${model.queries.find(q => q.name === 'findById') ? '' : `static async findById(con: dao.Connection, ${model.pkeys.map(k => `${k.alias || k.name}: ${k.retype || k.type}`).join(', ')}, optional: boolean = false): Promise<${model.name}> { |
88334
1934