* 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)
| 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. |
no test coverage detected