MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / getForDelete

Method getForDelete

lib/mapping/object-selector.js:251–287  ·  view source on GitHub ↗

* Gets the tables that should be used to execute the DELETE query. * @param {Client} client * @param {ModelMappingInfo} info * @param {Array} propertiesInfo * @param {Array} when * @return {Promise >} A promise that resolves to an Array of tables.

(client, info, propertiesInfo, when)

Source from the content-addressed store, hash-verified

249 * @return {Promise<Array<TableMetadata>>} A promise that resolves to an Array of tables.
250 */
251 static getForDelete(client, info, propertiesInfo, when) {
252 return Promise.all(info.tables.filter(t => !t.isView).map(t => client.metadata.getTable(info.keyspace, t.name)))
253 .then(tables => {
254 const filteredTables = tables
255 .filter((table, i) => {
256 if (table === null) {
257 throw new Error(`Table "${info.tables[i].name}" could not be retrieved`);
258 }
259
260 // All partition and clustering keys from the table should be included in the document
261 const keyNames = table.partitionKeys.concat(table.clusteringKeys).map(k => k.name);
262 const columns = propertiesInfo.map(p => p.columnName);
263
264 for (let i = 0; i < keyNames.length; i++) {
265 if (columns.indexOf(keyNames[i]) === -1) {
266 return false;
267 }
268 }
269
270 // "when" conditions should be contained in the table
271 return when.reduce((acc, p) => acc && table.columnsByName[p.columnName] !== undefined, true);
272 });
273
274 if (filteredTables.length === 0) {
275 let message = `No table matches (all PKs have to be specified) fields: [${
276 propertiesInfo.map(p => p.columnName)}]`;
277
278 if (when.length > 0) {
279 message += `; condition: [${when.map(p => p.columnName)}]`;
280 }
281
282 throw new Error(message);
283 }
284
285 return filteredTables;
286 });
287 }
288}
289
290function contains(arr, fn) {

Callers 1

createDeleteQueriesMethod · 0.80

Calls 1

getTableMethod · 0.65

Tested by

no test coverage detected