Replies: 4 comments 4 replies
-
Coulf you please paste an example of your code |
Beta Was this translation helpful? Give feedback.
-
Here is the sample of the object I am sending: Here is the code to save this object to my db: |
Beta Was this translation helpful? Give feedback.
-
you can have custom serialization if you pass a parameter with https://github.com/mysqljs/mysql#escaping-query-values
example: function JSONColumnParameter(value) {
return {
toSqlString() => `'${JSON.stringify(value)}'`;
}
}
let object = {id: '1232321412', title: 'ertert', link: 'https://dget.com/fret', tags: JSONColumnParameter(['sfef','dsds','sfsfs']), date: '32424000'};
query database const [rows, fields] = await connection.query('INSERT INTO TABLE SET ?', [object]); Alternatively just |
Beta Was this translation helpful? Give feedback.
-
I am using execute command to insert an object into my table with SET. For that, I am using
mysql.format
method.When I send data like this: ["one", "two", "three"], the format method removes the array brackets. It causes errors.
check the manual that corresponds to your MySQL server version for the right syntax to use near ''eew', 'qwerty'
What is the workaround for this?
[edit]: sorry, the same error persist if I don't use format and use query instead of execute.
Beta Was this translation helpful? Give feedback.
All reactions