* @param {String} keyspaceName * @param {String} name * @param {Object} cache * @param {Boolean} virtual * @returns {Promise }
(keyspaceName, name, cache, virtual)
| 128 | * @returns {Promise<TableMetadata|null>} |
| 129 | */ |
| 130 | async getTable(keyspaceName, name, cache, virtual) { |
| 131 | let tableInfo = cache && cache[name]; |
| 132 | if (!tableInfo) { |
| 133 | tableInfo = new TableMetadata(name); |
| 134 | if (cache) { |
| 135 | cache[name] = tableInfo; |
| 136 | } |
| 137 | } |
| 138 | if (tableInfo.loaded) { |
| 139 | return tableInfo; |
| 140 | } |
| 141 | if (tableInfo.loading) { |
| 142 | // Wait for it to emit |
| 143 | return promiseUtils.fromEvent(tableInfo, 'load'); |
| 144 | } |
| 145 | try { |
| 146 | // its not cached and not being retrieved |
| 147 | tableInfo.loading = true; |
| 148 | let indexRows; |
| 149 | let virtualTable = virtual; |
| 150 | const selectTable = virtualTable ? _selectVirtualTable : this.selectTable; |
| 151 | const query = util.format(selectTable, keyspaceName, name); |
| 152 | let tableRow = await this._getFirstRow(query); |
| 153 | // if we weren't sure if table was virtual or not, query virtual schema. |
| 154 | if (!tableRow && this.supportsVirtual && virtualTable === undefined) { |
| 155 | const query = util.format(_selectVirtualTable, keyspaceName, name); |
| 156 | try { |
| 157 | tableRow = await this._getFirstRow(query); |
| 158 | } |
| 159 | catch (err) { |
| 160 | // we can't error here as we can't be sure if the node |
| 161 | // supports virtual tables, in this case it is adequate |
| 162 | // to act as if there was no matching table. |
| 163 | } |
| 164 | if (tableRow) { |
| 165 | // We are fetching a virtual table |
| 166 | virtualTable = true; |
| 167 | } |
| 168 | } |
| 169 | if (!tableRow) { |
| 170 | tableInfo.loading = false; |
| 171 | tableInfo.emit('load', null, null); |
| 172 | return null; |
| 173 | } |
| 174 | const selectColumns = virtualTable ? _selectVirtualColumns : this.selectColumns; |
| 175 | const columnRows = await this._getRows(util.format(selectColumns, keyspaceName, name)); |
| 176 | if (this.selectIndexes && !virtualTable) { |
| 177 | indexRows = await this._getRows(util.format(this.selectIndexes, keyspaceName, name)); |
| 178 | } |
| 179 | await this._parseTableOrView(tableInfo, tableRow, columnRows, indexRows, virtualTable); |
| 180 | tableInfo.loaded = true; |
| 181 | tableInfo.emit('load', null, tableInfo); |
| 182 | return tableInfo; |
| 183 | } |
| 184 | catch (err) { |
| 185 | tableInfo.emit('load', err, null); |
| 186 | throw err; |
| 187 | } |
nothing calls this directly
no test coverage detected