# Mapper

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="index.html">mapping</a>~</span>Mapper<span class="signature">(client, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>Represents an object mapper for Apache Cassandra and DataStax Enterprise.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="Mapper"><span class="type-signature"></span>new Mapper<span class="signature">(client, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Creates a new instance of Mapper.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>client</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../Client.html">Client</a></span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            

            <td class="description last"><p>The Client instance to use to execute the queries and fetch the metadata.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>options</code></td>
            

            <td class="type">
            
                
<span class="param-type">MappingOptions</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The <a href="index.html#~MappingOptions">MappingOptions</a> containing the
information of the models and table mappings.</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/mapping/mapper.js#L44" target="_blank" rel="noopener">mapping/mapper.js, line 44</a></p></div>



















    <h5>Examples</h5>
    
        <p class="code-caption">Creating a Mapper instance with some options for the model 'User'</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>const mappingOptions = {
  models: {
    'User': {
      tables: ['users'],
      mappings: new UnderscoreCqlToCamelCaseMappings(),
      columnNames: {
        'userid': 'id'
      }
    }
  }
};
const mapper = new Mapper(client, mappingOptions);</pre></div></div>

        <p class="code-caption">Creating a Mapper instance with other possible options for a model</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>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);</pre></div></div>



    
    

    

    

    

    

    

    

    
        </div>

## Members

<div class="jsdoc-content">

        
            
<h4 class="name" id="client"><span class="type-signature"></span>client<span class="type-signature"> :<a href="../Client.html">Client</a></span></h4>




<div class="description">
    <p>The Client instance used to create this Mapper instance.</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type"><a href="../Client.html">Client</a></span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/mapping/mapper.js#L63" target="_blank" rel="noopener">mapping/mapper.js, line 63</a></p></div>






        
    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="batch"><span class="type-signature"></span>batch<span class="signature">(items, executionOptions<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise&lt;Result>}</span></h4>
    

    



<div class="description">
    <p>Executes a batch of queries represented in the items.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>items</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;ModelBatchItem></span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>executionOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>
|

<span class="param-type">String</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>An object containing the options to be used for the requests
execution or a string representing the name of the execution profile.</p>
                <h6>Properties</h6>
                

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>executionProfile</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>The name of the execution profile.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>isIdempotent</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>Defines whether the query can be applied multiple times without
changing the result beyond the initial application.</p>
<p>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.</p>
<p>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.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>logged</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    true
                
                </td>
            

            <td class="description last"><p>Determines whether the batch should be written to the batchlog.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>timestamp</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>
|

<span class="param-type">Long</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>The default timestamp for the query in microseconds from the
unix epoch (00:00:00, January 1st, 1970).</p></td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/mapping/mapper.js#L142" target="_blank" rel="noopener">mapping/mapper.js, line 142</a></p></div>















<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A Promise that resolves to a <a href="Result.html">Result</a>.</p>
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise&lt;Result></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="forModel"><span class="type-signature"></span>forModel<span class="signature">(name)</span><span class="type-signature"> &rarr; {ModelMapper}</span></h4>
    

    



<div class="description">
    <p>Gets a <a href="ModelMapper.html">ModelMapper</a> that is able to map documents of a certain model into
CQL rows.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>name</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            

            

            <td class="description last"><p>The name to identify the model. Note that the name is case-sensitive.</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/mapping/mapper.js#L78" target="_blank" rel="noopener">mapping/mapper.js, line 78</a></p></div>















<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A <a href="ModelMapper.html">ModelMapper</a> instance.</p>
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">ModelMapper</span>


    </dd>
</dl></div>
