question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support key value object place holder

See original GitHub issue

please support something like

p.execute("INSERT INTO chat_alert_item SET ?", {col1: value1, col2: value2});

you can see similar example in the documentation of npm mysql

var post  = {id: 1, title: 'Hello MySQL'};
var query = connection.query('INSERT INTO posts SET ?', post, function (error, results, fields) {
  if (error) throw error;
  // Neat!
});
console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'

currently in your implementation it gives

    at PoolConnection.execute (/usr/src/app/node_modules/mysql2/lib/connection.js:688:20)
    at /usr/src/app/node_modules/mysql2/lib/pool.js:180:29
    at /usr/src/app/node_modules/mysql2/lib/pool.js:36:14
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
muayyad-alsadicommented, Jun 14, 2018

thank you for your suggestion

but from the readme of this project

MySQL2 project is a continuation of MySQL-Native… and api changed to match popular mysqljs/mysql. MySQL2 is mostly API compatible with Node MySQL. You should check their API documentation to see all available API options. If you find any incompatibility with Node MySQL, Please report via Issue tracker. We will fix reported incompatibility on priority basis.

this means if it works in mysqljs/mysql it should work here. the code snippet is from their readme, it’s not only a valid use case, but it’s by the book.

just use .query()

isn’t .query is for select, while .execute for updates/insert?

use format + execute: p.execute(mysql.format(“INSERT INTO chat_alert_item SET ?”, {col1: value1, col2: value2}))

then it p.execute() should use mysql.format internally

expand manually ( preferred way, maybe we should add helper to automate this?)

yes, this is what I did

let cols = Object.keys(row).join('=?, ')+'=?';
pool.execute("INSERT INTO chat_alert_item SET "+cols, Object.values(row));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Putting placeholders in a key/value List based on a Set of keys ...
What's a good way to do this in Java? Replace the Set<Long> and List<Object[]> by a Map<Long, BigInteger> . If ...
Read more >
Zendesk Support placeholders reference
Zendesk Support placeholders are containers for dynamically generated ticket and user data. The format is a data reference contained within ...
Read more >
Advanced: Placeholders | Jira Service Management Data ...
The placeholders available are all the attributes available in the create/edit dialog. The value of the attribute with the same name as the...
Read more >
Placeholder objects - Micro Focus
You can use the following objects in a placeholder: sm : Refers to the value of a field in Service Manager. You can...
Read more >
Assigning a Value Set to a Placeholder Object - EPLAN Help
If a placeholder object has different value sets then, when editing the placeholder object later, you can switch between the different value sets....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found