/* * Copyright DataStax, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; const Tree = require('./tree'); const moduleBatchItemModule = require('./model-batch-item'); const InsertModelBatchItem = moduleBatchItemModule.InsertModelBatchItem; const UpdateModelBatchItem = moduleBatchItemModule.UpdateModelBatchItem; const RemoveModelBatchItem = moduleBatchItemModule.RemoveModelBatchItem; /** * Provides utility methods to group multiple mutations on a single batch. * @alias module:mapping~ModelBatchMapper */ class ModelBatchMapper { /** * Creates a new instance of model batch mapper. *
* An instance of this class is exposed as a singleton in the batching
field of the
* [ModelMapper]{@link module:mapping~ModelMapper}. Note that new instances should not be create with this
* constructor.
*
Please note that using IF NOT EXISTS will incur a non negligible performance cost so this should be used * sparingly.
* @returns {ModelBatchItem} A [ModelBatchItem]{@link module:mapping~ModelBatchItem} instance representing a query * or a set of queries to be included in a batch. */ insert(doc, docInfo) { return new InsertModelBatchItem(doc, docInfo, this._handler, this._cache.insert); } /** * Gets a [ModelBatchItem]{@link module:mapping~ModelBatchItem} containing the queries for the UPDATE mutation to be * used in a batch execution. * @param {Object} doc An object containing the properties to update. * @param {Object} [docInfo] An object containing the additional document information. * @param {Array* Please note that using IF conditions will incur a non negligible performance cost on the server-side so this * should be used sparingly. *
* @param {Object} [docInfo.when] A document that act as the condition that has to be met for the UPDATE to occur. * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS). ** Please note that using IF conditions will incur a non negligible performance cost on the server-side so this * should be used sparingly. *
* @returns {ModelBatchItem} A [ModelBatchItem]{@link module:mapping~ModelBatchItem} instance representing a query * or a set of queries to be included in a batch. */ update(doc, docInfo) { return new UpdateModelBatchItem(doc, docInfo, this._handler, this._cache.update); } /** * Gets a [ModelBatchItem]{@link module:mapping~ModelBatchItem} containing the queries for the DELETE mutation to be * used in a batch execution. * @param {Object} doc A document containing the primary keys values of the document to delete. * @param {Object} [docInfo] An object containing the additional doc information. * @param {Object} [docInfo.when] A document that act as the condition that has to be met for the DELETE to occur. * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS). * When the CQL query is generated, this would be used to generate the `IF` clause. ** Please note that using IF conditions will incur a non negligible performance cost on the server-side so this * should be used sparingly. *
* @param {Boolean} [docInfo.ifExists] When set, it only issues the DELETE command if the row already exists on the * server. ** Please note that using IF conditions will incur a non negligible performance cost on the server-side so this * should be used sparingly. *
* @param {Array