-
Notifications
You must be signed in to change notification settings - Fork 192
Closed
Description
I'm trying to implement "upsert" functionality that works across MySQL, Postgres and SQLite.
I haven't found one way to get it working in all three but I have a solution using ON CONFLICT in Postgres and REPLACE in MySQL and SQLite.
I've implemented it like so:
upsert(key, value) {
let upsert = `REPLACE INTO keyv (key, value) VALUES ("${key}", "${value}")`;
if(this.sql.dialectName === 'postgres') {
upsert = this.entry
.insert({ key, value })
.onConflict({ columns: ['key'], update: ['value'] })
.toString();
}
return this.query(upsert);
}As far as I can see there's no way to use REPLACE with node-sql. Is that correct? Would it be simple to implement?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels