Browse Source

add knex section and function for insert on duplicated to mariadb/mysql

master
Markus Bergholz 3 years ago
parent
commit
9bf1b7e2e2
  1. 12
      til.md

12
til.md

@ -265,4 +265,16 @@ http {
}
}
}
```
# knex
insert on duplicated for MariaDB/MySQL
```javascript
async function insert_on_duplicated(table, data){
let insert = knex(table).insert(data).toString();
let update = knex(table).update(data).toString().replace(/^update .* set /i, '');
return await knex.raw(`${insert} on duplicate key update ${update}`);
}
```
Loading…
Cancel
Save