Class: 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.

Source:
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

client :Client

The Client instance used to create this Mapper instance.

Type:
Source:

Methods

batch(items, executionOptionsopt) → {Promise.<Result>}

Executes a batch of queries represented in the items.

Parameters:
Name Type Attributes Description
items Array.<ModelBatchItem>
executionOptions Object | String <optional>

An object containing the options to be used for the requests execution or a string representing the name of the execution profile.

Properties
Name Type Attributes Default Description
executionProfile String <optional>

The name of the execution profile.

isIdempotent Boolean <optional>

Defines whether the query can be applied multiple times without changing the result beyond the initial application.

The mapper uses the generated queries to determine the default value. When an UPDATE is generated with a counter column or appending/prepending to a list column, the execution is marked as not idempotent.

Additionally, the mapper uses the safest approach for queries with lightweight transactions (Compare and Set) by considering them as non-idempotent. Lightweight transactions at client level with transparent retries can break linearizability. If that is not an issue for your application, you can manually set this field to true.

logged Boolean <optional>
true

Determines whether the batch should be written to the batchlog.

timestamp Number | Long <optional>

The default timestamp for the query in microseconds from the unix epoch (00:00:00, January 1st, 1970).

Source:
Returns:

A Promise that resolves to a Result.

Type
Promise.<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.

Source:
Returns:

A ModelMapper instance.

Type
ModelMapper