knex-on-duplicate-update
Advanced tools
Comparing version 2.1.3 to 2.2.0
@@ -13,23 +13,27 @@ const Knex = require('knex'); | ||
const { placeholders, bindings } = columns.reduce((result, column) => { | ||
if (typeof column === 'string') { | ||
result.placeholders.push(`??=Values(??)`); | ||
result.bindings.push(column, column); | ||
} else if (column && typeof column === 'object') { | ||
Object.keys(column).forEach((key) => { | ||
result.placeholders.push(`??=?`); | ||
result.bindings.push(key, column[key]); | ||
}); | ||
} else { | ||
throw new Error('onDuplicateUpdate error: expected column name to be string or object.'); | ||
} | ||
const { placeholders, bindings } = columns.reduce( | ||
(result, column) => { | ||
if (typeof column === 'string') { | ||
result.placeholders.push(`??=Values(??)`); | ||
result.bindings.push(column, column); | ||
} else if (column && typeof column === 'object') { | ||
Object.keys(column).forEach((key) => { | ||
result.placeholders.push(`??=?`); | ||
result.bindings.push(key, column[key]); | ||
}); | ||
} else { | ||
throw new Error('onDuplicateUpdate error: expected column name to be string or object.'); | ||
} | ||
return result; | ||
}, { placeholders: [], bindings: [] }); | ||
return result; | ||
}, | ||
{ placeholders: [], bindings: [] } | ||
); | ||
const { | ||
sql: originalSQL, | ||
bindings: originalBindings, | ||
} = this.toSQL(); | ||
const { sql: originalSQL, bindings: originalBindings } = this.toSQL(); | ||
if (!originalBindings.length) { | ||
throw new Error('onDuplicateUpdate error: empty insert statement.'); | ||
} | ||
const newBindings = [...originalBindings, ...bindings]; | ||
@@ -39,5 +43,5 @@ | ||
`${originalSQL} on duplicate key update ${placeholders.join(', ')}`, | ||
newBindings, | ||
newBindings | ||
); | ||
}); | ||
}; |
{ | ||
"name": "knex-on-duplicate-update", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"description": "Simple patcher for Knex. It adds the .onDuplicateUpdate() function to knex's query builder.", | ||
"keywords": [ | ||
"knex", | ||
"on duplicate update", | ||
"upsert" | ||
], | ||
"homepage": "https://github.com/felixmosh/knex-on-duplicate-update#readme", | ||
"bugs": { | ||
"url": "https://github.com/felixmosh/knex-on-duplicate-update/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/felixmosh/knex-on-duplicate-update.git" | ||
}, | ||
"license": "ISC", | ||
"author": "Felixmosh", | ||
"main": "lib/index.js", | ||
@@ -12,38 +27,29 @@ "types": "types.d.ts", | ||
"scripts": { | ||
"release": "release-it", | ||
"test": "jest", | ||
"test:types": "tsd", | ||
"version": "auto-changelog -p && git add CHANGELOG.md", | ||
"release": "release-it" | ||
"version": "auto-changelog -p && git add CHANGELOG.md" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/felixmosh/knex-on-duplicate-update.git" | ||
"lint-staged": { | ||
"*.ts": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"keywords": [ | ||
"knex", | ||
"on duplicate update", | ||
"upsert" | ||
], | ||
"author": "Felixmosh", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/felixmosh/knex-on-duplicate-update/issues" | ||
"jest": { | ||
"testEnvironment": "node" | ||
}, | ||
"homepage": "https://github.com/felixmosh/knex-on-duplicate-update#readme", | ||
"peerDependencies": { | ||
"knex": ">= 0.95.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.0.1", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^16.6.1", | ||
"auto-changelog": "^2.2.1", | ||
"dotenv": "^10.0.0", | ||
"jest": "^27.0.6", | ||
"knex": "0.95.9", | ||
"auto-changelog": "^2.4.0", | ||
"dotenv": "^16.0.0", | ||
"jest": "^27.5.1", | ||
"knex": "1.0.6", | ||
"mysql": "^2.18.1", | ||
"release-it": "^14.4.1", | ||
"tsd": "^0.17.0" | ||
"prettier": "^2.6.2", | ||
"release-it": "^14.14.2", | ||
"tsd": "^0.20.0" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node" | ||
"peerDependencies": { | ||
"knex": ">= 0.95.1" | ||
}, | ||
@@ -72,3 +78,4 @@ "release-it": { | ||
} | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
6507
51
10