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

Method getForInsert

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

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

(client, info, propertiesInfo)

Source from the content-addressed store, hash-verified

141 * @return {Promise<Array<TableMetadata>>} A promise that resolves to an Array of tables.
142 */
143 static getForInsert(client, info, propertiesInfo) {
144 return Promise.all(info.tables.filter(t => !t.isView).map(t => client.metadata.getTable(info.keyspace, t.name)))
145 .then(tables => {
146 const filteredTables = tables
147 .filter((table, i) => {
148 if (table === null) {
149 throw new Error(`Table "${info.tables[i].name}" could not be retrieved`);
150 }
151
152 if (keysAreIncluded(table.partitionKeys, propertiesInfo) !== keyMatches.all) {
153 // Not all the partition keys are covered
154 return false;
155 }
156
157 const clusteringKeyMatches = keysAreIncluded(table.clusteringKeys, propertiesInfo);
158
159 // All clustering keys should be included or it can be inserting a static column value
160 if (clusteringKeyMatches === keyMatches.all) {
161 return true;
162 }
163
164 if (clusteringKeyMatches === keyMatches.some) {
165 return false;
166 }
167
168 const staticColumns = staticColumnCount(table);
169 return propertiesInfo.length === table.partitionKeys.length + staticColumns && staticColumns > 0;
170 });
171
172 if (filteredTables.length === 0) {
173 throw new Error(`No table matches (all PKs have to be specified) fields: [${
174 propertiesInfo.map(p => p.columnName)}]`);
175 }
176
177 return filteredTables;
178 });
179 }
180
181 /**
182 * Gets the tables that should be used to execute the UPDATE query.

Callers 1

createInsertQueriesMethod · 0.80

Calls 3

keysAreIncludedFunction · 0.85
staticColumnCountFunction · 0.85
getTableMethod · 0.65

Tested by

no test coverage detected