Every line of 'sequelize bulk update' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
371 async createBulk(model, data, options) { 372 if (data.length > 1000) { 373 const chunks = []; 374 let i = 0; 375 while (i < data.length) { 376 chunks.push(data.slice(i, i + 1000)); 377 i += 1000; 378 } 379 const ids_all = []; 380 for (const chunk of chunks) { 381 [].push.apply(ids_all, await this.createBulk(model, chunk, options)); 382 } 383 return ids_all; 384 } 385 let result; 386 try { 387 result = (await this._collection(model).insertMany(data, { safe: true })); 388 } 389 catch (error) { 390 throw _processSaveError(error); 391 } 392 let error; 393 const ids = result.ops.map((doc) => { 394 const id = _objectIdToString(doc._id); 395 if (id) { 396 delete doc._id; 397 } 398 else { 399 error = new Error('unexpected result'); 400 } 401 return id; 402 }); 403 if (error) { 404 throw error; 405 } 406 else { 407 return ids; 408 } 409 }
377 public async createBulk(model: string, data: any[], options: { transaction?: Transaction }) { 378 if (data.length > 1000) { 379 const chunks = []; 380 let i = 0; 381 while (i < data.length) { 382 chunks.push(data.slice(i, i + 1000)); 383 i += 1000; 384 } 385 const ids_all: any = []; 386 for (const chunk of chunks) { 387 [].push.apply(ids_all, await this.createBulk(model, chunk, options)); 388 } 389 return ids_all; 390 } 391 let result: any; 392 try { 393 result = (await this._collection(model).insertMany(data, { safe: true })); 394 } catch (error) { 395 throw _processSaveError(error); 396 } 397 let error; 398 const ids = result.ops.map((doc: any) => { 399 const id = _objectIdToString(doc._id); 400 if (id) { 401 delete doc._id; 402 } else { 403 error = new Error('unexpected result'); 404 } 405 return id; 406 }); 407 if (error) { 408 throw error; 409 } else { 410 return ids; 411 } 412 }
221 async updateAll (object) { 222 if (!Object.isObject(object)) { 223 throw new Error('updateAll params must an object') 224 } 225 return this.runSql(this._sqlFormatter.toSql({opUpdate: object})) 226 }
69 async updateMany(query, updates) { 70 const docs = await this.find(query, { fields: { _id: 1 } }); 71 const result = await this.collection.updateMany(query, { 72 $set: Object.assign({}, updates, { 73 updatedAt: new Date().toISOString() 74 }) 75 }); 76 this.loader.clearAll(); 77 const ids = docs.map((d) => d._id); 78 this.findManyById(ids); 79 ids.forEach(async (id) => { 80 this.pubsub.publish( 81 `${this.typeSingular}Updated`, 82 { [`${this.typeSingular}Updated`]: await this.findOneById(id) } 83 ); 84 }); 85 return result; 86 }
49 async function bulkInsert(client, each) { 50 await each(async function (data) { 51 await insertOne(client, data); 52 }); 53 }
144 async updateMany(query: object, data: Partial): Promise { 145 await this.model.sync(); 146 this.removeIdAndTimeStamps(data); 147 148 await this.model.update(data, { 149 where: query, 150 }); 151 }
18 update (query, data) { 19 return this.table.updateOne(query, { 20 $set: data 21 }); 22 }
97 function insertList(key, value) { 98 return module.exports.listsCollection.updateOne({ _id: key }, { $set: { value } }, { upsert: true }); 99 }
35 public async update(query: T, newValue: T, multi = false): Promise { 36 return await this.performOperation('update', { query, value: newValue, multi }); 37 }
358 async updateMany(collectionName: string, query: ObjectLiteral, update: ObjectLiteral, options?: { upsert?: boolean, w?: any, wtimeout?: number, j?: boolean }): Promise { 359 return await this.getCollection(collectionName).updateMany(query, update, options); 360 }