# RustSession

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>RustSession<span class="signature">()</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>The native session of the driver.</p>
<p>Rust gives the session to JS as an <code>External</code>, not as an instance of a native class.
A method call on an instance of a native class costs <code>napi_unwrap</code> and a borrow check
of napi-rs. JS uses the session in each execution, so this cost adds up.
This class gives the session the same methods that the native class had.
Each method calls one Rust function with the <code>External</code>.</p>
<p>This class also owns the values frames of the session.
Its methods take the values, encode them into a frame, and pass the frame to Rust.
A frame is a view of one shared <a href="FrameWriter.html">FrameWriter</a> buffer, and the next frame overwrites it.
Thus, these rules keep concurrent requests from sending each other's values:</p>
<ul>
<li>A frame never leaves this class. Callers cannot keep one across an <code>await</code>.</li>
<li>Each method that writes a frame is not <code>async</code>.
Thus, <code>await</code> between writing the frame and the native call is a compile error.
Do not make these methods <code>async</code>.</li>
<li>Rust copies the frame before the native call returns.</li>
</ul></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="RustSession"><span class="type-signature"></span>new RustSession<span class="signature">()</span><span class="type-signature"></span></h4>
    

    















<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/rust-session.ts#L42" target="_blank" rel="noopener">rust-session.ts, line 42</a></p></div>




















    
    

    

    

    

    

    

    

    
        </div>

## Members

<div class="jsdoc-content">

        
            
<h4 class="name" id="inner"><span class="type-signature"></span>inner<span class="type-signature"></span></h4>




<div class="description">
    <p>The native session, for the Rust functions that take it as an argument.</p>
</div>







<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/rust-session.ts#L67" target="_blank" rel="noopener">rust-session.ts, line 67</a></p></div>






        
    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="batch"><span class="type-signature"></span>batch<span class="signature">(types, params)</span><span class="type-signature"></span></h4>
    

    











    <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>types</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>The expected types, one list for each statement.</p></td>
        </tr>

    

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

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>The values, one array for each statement.</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.7.1/lib/rust-session.ts#L141" target="_blank" rel="noopener">rust-session.ts, line 141</a></p></div>




















        
            

    

    
    <h4 class="name" id="batchPrepared"><span class="type-signature"></span>batchPrepared<span class="signature">(types, params)</span><span class="type-signature"></span></h4>
    

    











    <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>types</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>The expected types, one list for each statement.</p></td>
        </tr>

    

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

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>The values, one array for each statement.</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.7.1/lib/rust-session.ts#L159" target="_blank" rel="noopener">rust-session.ts, line 159</a></p></div>




















        
            

    

    
    <h4 class="name" id="computeToken"><span class="type-signature"></span>computeToken<span class="signature">(components)</span><span class="type-signature"></span></h4>
    

    











    <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>components</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>The partition key values, already encoded.
<code>null</code> is null, and <code>undefined</code> is unset.</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.7.1/lib/rust-session.ts#L201" target="_blank" rel="noopener">rust-session.ts, line 201</a></p></div>




















        
            

    

    
    <h4 class="name" id=".create"><span class="type-signature">(async, static) </span>create<span class="signature">(encoder)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Creates a session based on the provided session options.</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>encoder</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>Encodes the values of the requests of this session.</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.7.1/lib/rust-session.ts#L59" target="_blank" rel="noopener">rust-session.ts, line 59</a></p></div></div>
