Koa+mysql, has been deleted in batches. How to update and insert in batches?

problem description

how does koa+mysql, implement batch update and batch insert,

realized batch deletions

clipboard.png

sql

// id
let cartDelectById = (id) => {
        let sql = `delete from cart where cart_id = ${id};`
        return query(sql)
    }
    // id
let cartDelectByIds = (ids) => {
    let sql = `delete from cart where cart_id in (${ids});`
    return query(sql)
}

koa

// 
const cartDelectById = async(ctx) => {
        let id = 1;
        await cartModel.cartDelectById([id])
            .then(result => {
                ctx.body = {
                    state: 200,
                    msg: "",
                    data: result
                }
            })
            .catch(error => {
                console.log(error);
                ctx.body = false;
            })
    }
// 
const cartDelectByIds = async(ctx) => {
    let ids = [1, 2, 3];
    await cartModel.cartDelectByIds(ids)
        .then(result => {
            ctx.body = {
                state: 200,
                msg: "",
                data: result
            }
        })
        .catch(error => {
            console.log(error);
            ctx.body = false;
        })
}

A single sql is successfully inserted and updated. How to achieve batch update and batch insert

// 
let cartInsertInto = (values) => {
    let sql = `insert into cart values(default,?,?,?,?,?);`
    return query(sql, values)
}
// 
let cartUpdate = (values) => {
    let sql = `update cart set user_id=?,goods_id=?,cart_goods_number=? where cart_id=?;`
    return query(sql)
}

insert

const cartInsertInto = async(ctx) => {
    console.log(ctx.request.body)
    let goodsId = ctx.request.body.goodsId;
    let cartGoodsNumber = ctx.request.body.goodsNumber;
    let userId = ctx.request.body.userId;
    await cartModel.cartInsertInto([userId, goodsId, cartGoodsNumber, new Date(), new Date()])
        .then(result => {
            ctx.body = {
                state: 200,
                msg: "",
                data: result
            }
        })
        .catch(error => {
            console.log(error);
            ctx.body = false;
        })
}

let cartDelectById = (id) => {
    const sql = `delete from cart where cart_id in (${id.join(',')});`
    return query(sql)
}

this function can be passed into the array instead.
Note: it is recommended that your SQL add SQL preprocessing mechanism to prevent SQL injection

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e487a3-66659.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e487a3-66659.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?