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

Method forModel

lib/mapping/mapper.js:89–115  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Calls 3

createDefaultMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected