I need to convert a javascript array to a sql list

zzzzzz

so i have this req -

app.delete("/delete/:sku", (req, res) => {
const sku = req.params.sku;
db.query(DELETE FROM products WHERE sku IN(?)

the console.log(req.params.sku) results in - wefwefwef,erferferfrgrwb,23r23r on the console,

i need to convert the sku string to a SQL list so i can insert the values for the IN clause.

The Fool

You should use a parameterized query. This could look something like this.

const sku = req.params.sku.split(',');
const ins = new Array(sku.length).fill('?').join();
db.query(`DELETE FROM products WHERE sku IN (${ins})`, sku);

If you need to give the params names like @p1, then something like this

const sku = req.params.sku.split(',');
const ins = sku.map((_, i) => `@p${i}`).join();
db.query(`DELETE FROM products WHERE sku IN (${ins})`, sku);

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I need to convert a specially formatted string to an javascript array

i need to convert Json to array and i'm need to read this array

How do I convert java.sql.Array to List<MyCustomEnum>?

How do I convert a C# List<string[]> to a Javascript array?

JavaScript Object with children need to convert into SQL like Array (nosql data format to sql)

I need to convert this string into a list in Python

I need an algorithmic help to convert an input Array object to ArrayList<List<Integer>> object?

i need to convert array value to json in jquery

Convert Java List to Javascript Array

I need to convert a binary string to ascii array using javascript. (UTF-16 to ascii conversion)

How to convert a list to an array as there is a need to take transpose in Python?

i have an array and i need to change an array format using javascript

need to convert sql query to linq and return list of records

How to convert a python list of tuples to an array in JavaScript?

convert string with square brackets to array or list in Javascript

How to convert a DOM node list to an array in Javascript?

Convert a Java List<String> into a Javascript array

How to convert javascript array to specific list of objects

how to convert json to array in javascript for an li list

Javascript Convert String to Object(list/array)

How to convert word list to array in JavaScript

I need to convert an int parameter into a linked list field

How can i use dos batch file to get a list of folders in a folder and convert it into a javascript array?

How I convert string response into Array List

Can i Convert this array to List or Set in Typescript?

Why should I convert List into Array

I want to convert an python output list to an array

How do I convert an array or a list into a hashref?

I need to convert this Json Facebook Pages to array for select