leo-connector-postgres
Advanced tools
Comparing version
@@ -123,7 +123,28 @@ "use strict"; | ||
let deletedValue = settings.deleted_value || (deletedColumn.match(/end/) ? 'current_timestamp::timestamp' : true); | ||
let auditdateColumn = settings.auditdate_column || "_auditdate"; | ||
let auditdate = settings.delete_set_auditdate ? `, ${auditdateColumn} = current_timestamp::timestamp` : ""; | ||
let fullDeletes = settings.full_deletes === true; | ||
getFields(connection, event).then((table) => { | ||
let delQuery = `update ${tableName} set ${deletedColumn} = ${deletedValue} | ||
where ${settings.id_column} in (${data.ids.map(f=>escape(f))})`; | ||
let whereSql = where({ | ||
start: data.start, | ||
end: data.end | ||
}, settings); | ||
let delQuery = (fullDeletes ? `delete from ${tableName}` : `update ${tableName} set ${deletedColumn} = ${deletedValue} ${auditdate}`) + ` where ${settings.id_column} ${whereSql}`; | ||
let valid = false; | ||
if (data.ids) { | ||
delQuery += ` AND ${settings.id_column} in (${data.ids.map(f=>escape(f))}) `; | ||
valid = true; | ||
} | ||
if (data.not_ids && data.start && data.end) { | ||
delQuery += ` AND ${settings.id_column} not in (${data.not_ids.map(f=>escape(f))})`; | ||
valid = true; | ||
} | ||
if (!valid) { | ||
callback("ids or (not_ids, start, end) are required"); | ||
return; | ||
} | ||
logger.log("Delete Query", delQuery); | ||
@@ -130,0 +151,0 @@ connection.query(delQuery, (err) => { |
@@ -575,2 +575,2 @@ const { | ||
return client; | ||
} | ||
} |
@@ -377,8 +377,8 @@ "use strict"; | ||
where ${nk.map(id=>`prev.${id} = changes.${id}`).join(' and ')} and prev.${columnConfig._startdate} != now() and changes.isNew = false /*Need to make sure we are only updating the ones not just inserted through SCD2 otherwise we run into issues with multiple rows having .${columnConfig._current}*/ | ||
and (changes.runSCD1=1 OR changes.runSCD6=1 OR changes.runSCD2=1) | ||
and (changes.runSCD1=1 OR changes.runSCD6=1 OR (changes.runSCD2=1 and prev.${columnConfig._current})) | ||
`, done); | ||
}); | ||
tasks.push(done => connection.query(`drop table ${qualifiedStagingTable}_changes`, done)); | ||
tasks.push(done => connection.query(`drop table ${qualifiedStagingTable}`, done)); | ||
// tasks.push(done => connection.query(`drop table ${qualifiedStagingTable}_changes`, done)); | ||
// tasks.push(done => connection.query(`drop table ${qualifiedStagingTable}`, done)); | ||
async.series(tasks, err => { | ||
@@ -385,0 +385,0 @@ if (!err) { |
{ | ||
"name": "leo-connector-postgres", | ||
"version": "2.0.0-204-g5fcc0acd", | ||
"version": "2.0.0-210-gd7eece1", | ||
"description": "A Postgres database connector for use with Leo Platform", | ||
@@ -23,5 +23,5 @@ "repository": { | ||
"leo-connector-common": "entrata", | ||
"leo-sdk": "^2.2.0", | ||
"leo-sdk": "^2.2.4", | ||
"leo-streams": "^1.1.1", | ||
"pg": "^7.7.1", | ||
"pg": "^7.8.0", | ||
"pg-copy-streams": "^1.2.0", | ||
@@ -32,8 +32,6 @@ "pg-format": "^1.0.4", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.19.1", | ||
"event-stream": "^4.0.1", | ||
"mocha": "^5.0.5", | ||
"proxyquire": "^2.1.0", | ||
"sinon": "^4.4.8" | ||
"chai": "^4.2.0", | ||
"eslint": "^5.13.0", | ||
"mocha": "^5.2.0", | ||
"sinon": "^7.2.3" | ||
}, | ||
@@ -40,0 +38,0 @@ "config": { |
131651
0.55%4
-33.33%4153
0.48%Updated
Updated