Represents an object mapper for Apache Cassandra and DataStax Enterprise.

Members

Client

client

The Client instance used to create this Mapper instance.

Constructor

new

Mapper

(Client client, [MappingOptions options])

Creates a new instance of Mapper.

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);
Parameters:
Name Type Description
client Client

The Client instance to use to execute the queries and fetch the metadata.

options optional MappingOptions

The MappingOptions containing the information of the models and table mappings.

Methods

batch

(Array<ModelBatchItem> items, [Object or String executionOptions])

Executes a batch of queries represented in the items.

Parameters:
Name Type Description
items Array<ModelBatchItem>
executionOptions optional Object or String

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

executionOptions.executionProfile optional String

The name of the execution profile.

executionOptions.isIdempotent optional Boolean

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.

executionOptions.logged optional Boolean

Determines whether the batch should be written to the batchlog.

(default: true)
executionOptions.timestamp optional Number or Long

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

Returns:
Type Description
Promise<Result>

A Promise that resolves to a Result.

forModel

(String name)

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:
Type Description
ModelMapper

A ModelMapper instance.