# activerecord-spanner-adapter - Class ActiveRecordSpannerAdapter::Connection (v2.2.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.2.0 (latest)](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-Connection)
- [2.1.0](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/2.1.0/ActiveRecordSpannerAdapter-Connection)
- [2.0.0](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/2.0.0/ActiveRecordSpannerAdapter-Connection)
Reference documentation and code samples for the activerecord-spanner-adapter class ActiveRecordSpannerAdapter::Connection.

## Inherits

- Object

## Methods

### .database_path

    def self.database_path(config)

### .information_schema

    def self.information_schema(config)

### .reset_information_schemas!

    def self.reset_information_schemas!()

Clears the cached information about the underlying information schemas.
Call this method if you drop and recreate a database with the same name
to prevent the cached information to be used for the new database.

### .spanners

    def self.spanners(config)

### #abort_batch

    def abort_batch()

Aborts the current batch on this connection. This is a no-op if there is no batch on this connection.

### #active?

    def active?() -> Boolean

**Returns**

- (Boolean)

### #begin_transaction

    def begin_transaction(isolation = nil)

Transactions

### #commit_transaction

    def commit_transaction()

### #connect!

    def connect!()

**Alias Of** : [#session](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-Connection#ActiveRecordSpannerAdapter__Connection_session_instance_)

### #create_database

    def create_database()

Database Operations

### #create_transaction_after_failed_first_statement

    def create_transaction_after_failed_first_statement(original_error)

Creates a transaction using a BeginTransaction RPC. This is used if the first statement of a
transaction fails, as that also means that no transaction id was returned.

### #current_transaction

    def current_transaction()

Returns the value of attribute current_transaction.

### #current_transaction=

    def current_transaction=(value)

Sets the attribute current_transaction

### #database

    def database()

### #database_id

    def database_id()

Returns the value of attribute database_id.

### #ddl_batch

    def ddl_batch()

Executes a set of DDL statements as one batch. This method raises an error if no block is given.
**Raises**

- (Google::Cloud::FailedPreconditionError)
**Example**

```ruby
connection.ddl_batch do
  connection.execute_ddl "CREATE TABLE `Users` (Id INT64, Name STRING(MAX)) PRIMARY KEY (Id)"
  connection.execute_ddl "CREATE INDEX Idx_Users_Name ON `Users` (Name)"
end
```

### #ddl_batch?

    def ddl_batch?() -> Boolean

Returns true if this connection is currently executing a DDL batch, and otherwise false.
**Returns**

- (Boolean)

### #disconnect!

    def disconnect!()

### #execute_ddl

    def execute_ddl(statements, operation_id: nil, wait_until_done: true)

### #execute_query

    def execute_query(sql, params: nil, types: nil, single_use_selector: nil, request_options: nil)

DQL, DML Statements

### #execute_sql_request

    def execute_sql_request(sql, converted_params, types, selector, request_options = nil)

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

### #initialize

    def initialize(config) -> Connection

**Returns**

- ([Connection](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-Connection)) --- a new instance of Connection

### #instance_id

    def instance_id()

Returns the value of attribute instance_id.

### #isolation_level

    def isolation_level()

Returns the value of attribute isolation_level.

### #isolation_level=

    def isolation_level=(value)

Sets the attribute isolation_level

### #raise_aborted_err

    def raise_aborted_err()

### #reset!

    def reset!()

### #rollback_transaction

    def rollback_transaction()

### #run_batch

    def run_batch()

Runs the current batch on this connection. This will raise a FailedPreconditionError if there is no
active batch on this connection.

### #session

    def session()

**Aliases**

- [#connect!](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-Connection#ActiveRecordSpannerAdapter__Connection_connect!_instance_)

### #session_not_found?

    def session_not_found?(err) -> Boolean

**Returns**

- (Boolean)

### #spanner

    def spanner()

Returns the value of attribute spanner.

### #start_batch_ddl

    def start_batch_ddl()

Starts a manual DDL batch. The batch must be ended by calling either run_batch or abort_batch.
**Example**

```ruby
begin
  connection.start_batch_ddl
  connection.execute_ddl "CREATE TABLE `Users` (Id INT64, Name STRING(MAX)) PRIMARY KEY (Id)"
  connection.execute_ddl "CREATE INDEX Idx_Users_Name ON `Users` (Name)"
  connection.run_batch
rescue StandardError
  connection.abort_batch
  raise
end
```

### #transaction_not_found?

    def transaction_not_found?(err) -> Boolean

**Returns**

- (Boolean)

### #transaction_selector

    def transaction_selector()

### #truncate

    def truncate(table_name)