Was this page helpful?
Mapper¶
mapping~Mapper(client, optionsopt)
Represents an object mapper for Apache Cassandra and DataStax Enterprise.
Constructor¶
new Mapper(client, optionsopt)
Creates a new instance of Mapper.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
client |
Client | The Client instance to use to execute the queries and fetch the metadata. |
|
options |
MappingOptions |
<optional> |
The MappingOptions containing the information of the models and table mappings. |
Examples
Creating a Mapper instance with some options for the model 'User'
const mappingOptions = {
models: {
'User': {
tables: ['users'],
mappings: new UnderscoreCqlToCamelCaseMappings(),
columnNames: {
'userid': 'id'
}
}
}
};
const mapper = new Mapper(client, mappingOptions);Creating a Mapper instance with other possible options for a model
const mappingOptions = {
models: {
'Video': {
tables: ['videos', 'user_videos', 'latest_videos', { name: 'my_videos_view', isView: true }],
mappings: new UnderscoreCqlToCamelCaseMappings(),
columnNames: {
'videoid': 'id'
},
keyspace: 'ks1'
}
}
};
const mapper = new Mapper(client, mappingOptions);Members¶
Methods¶
batch(items, executionOptionsopt) → {Promise:.<Result:>}
Executes a batch of queries represented in the items.
Parameters:
Returns:
A Promise that resolves to a Result.
forModel(name) → {ModelMapper}
Gets a ModelMapper that is able to map documents of a certain model into CQL rows.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String | The name to identify the model. Note that the name is case-sensitive. |
Returns:
A ModelMapper instance.
- Type
- ModelMapper