Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142188

nested array for multiple row insert is getting stringify with sequelize nodejs

$
0
0

As per some answers i am using this type of array to insert multiple rows in mysql

[ [ 252456, 1, 55, '0' ],
[ 357083, 1, 56, '0' ],
[ 316493, 1, 57, '0' ] ]

so after this expected result was

INSERT INTO table (col1, col2, col3, col4) VALUES (252456,1,55,'0'), (357083,1,56,'0'), (316493,1,57,'0')

but actual query what is running is

INSERT INTO table (col1, col2, col3, col4) VALUES 252456,1,55,'0',357083,1,56,'0',316493,1,57,'0'

Can anyone help with he problem?? below is my code snippet

let get_rows = await db.sequelize.query("select col1, col1, col3, '0' as col4 from table1 where (condition1 = '3' || condition2 = '4') and condition3 = '0';", {replacements: [], type: db.sequelize.QueryTypes.SELECT});

    if(get_rows && get_rows.length){
        let insert_rows = get_rows.map(x => Object.values(x));

        await db.sequelize.query("INSERT INTO table (col1, col2, col3, col4) VALUES ?;", {replacements: [insert_rows], type: db.sequelize.QueryTypes.INSERT});
    };

Viewing all articles
Browse latest Browse all 142188

Trending Articles