* Gets a [ModelMapper]module:mapping~ModelMapper that is able to map documents of a certain model into * CQL rows. * @param {String} name The name to identify the model. Note that the name is case-sensitive. * @returns {ModelMapper} A [ModelMapper]module:mapping~ModelMapper
(name)
| 87 | * @returns {ModelMapper} A [ModelMapper]{@link module:mapping~ModelMapper} instance. |
| 88 | */ |
| 89 | forModel(name) { |
| 90 | let modelMapper = this._modelMappers.get(name); |
| 91 | |
| 92 | if (modelMapper === undefined) { |
| 93 | let mappingInfo = this._modelMappingInfos.get(name); |
| 94 | |
| 95 | if (mappingInfo === undefined) { |
| 96 | if (!this.client.keyspace) { |
| 97 | throw new Error(`No mapping information found for model '${name}'. ` + |
| 98 | `Mapper is unable to create default mappings without setting the keyspace`); |
| 99 | } |
| 100 | |
| 101 | mappingInfo = ModelMappingInfo.createDefault(name, this.client.keyspace); |
| 102 | this.client.log('info', `Mapping information for model '${name}' not found, creating default mapping. ` + |
| 103 | `Keyspace: ${mappingInfo.keyspace}; Table: ${mappingInfo.tables[0].name}.`); |
| 104 | } else { |
| 105 | this.client.log('info', `Creating model mapper for '${name}' using mapping information. Keyspace: ${ |
| 106 | mappingInfo.keyspace}; Table${mappingInfo.tables.length > 1? 's' : ''}: ${ |
| 107 | mappingInfo.tables.map(t => t.name)}.`); |
| 108 | } |
| 109 | |
| 110 | modelMapper = new ModelMapper(name, new MappingHandler(this.client, mappingInfo)); |
| 111 | this._modelMappers.set(name, modelMapper); |
| 112 | } |
| 113 | |
| 114 | return modelMapper; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Executes a batch of queries represented in the items. |
no test coverage detected