const json = [];
const insertUser = (data) => {
return new Promise((resolve, reject) => {
// 添加单个用户
fetch(url, {
// ...// 请求体和headers和method
})
.then(resolve)
.catch(reject);
});
};
async function inserUserList() {
let a = 0;
while (a < json.length) {
await insertUser(json[a])
.then((res) => {
console.log("res", res);
})
.catch((err) => {
console.log("err", err);
});
const time = await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(a);
}, 1000); // 防止服务器崩溃
});
a++;
console.log(time + "s");
}
}
inserUserList();
数据库批量插入数据
最新推荐文章于 2024-11-01 16:04:18 发布