Class: ActiveRecord::ConnectionAdapters::AwsDataServiceMysql::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret_arn:, resource_arn:, database:, **config) ⇒ Connection

Returns a new instance of Connection.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 45

def initialize(secret_arn:, resource_arn:, database:, **config)
  @client = ::Aws::RDSDataService::Client.new
  @secret_arn = secret_arn
  @resource_arn = resource_arn
  @database = database
  @query_options = {
    database_timezone: :local,
    as: :array, # Mysql2 default is hash
    symbolize_keys: false
  }
end

Instance Attribute Details

#query_optionsObject (readonly)

Returns the value of attribute query_options.



43
44
45
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 43

def query_options
  @query_options
end

Instance Method Details

#abandon_results!Object



69
70
71
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 69

def abandon_results!
  # nop
end

#affected_rowsObject



73
74
75
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 73

def affected_rows
  @last_result.number_of_records_updated
end

#begin_db_transactionObject



87
88
89
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 87

def begin_db_transaction
  @current_transaction = client.begin_transaction(secret_arn: secret_arn, resource_arn: resource_arn, database: database)
end

#closeObject



65
66
67
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 65

def close
  # nop
end

#commit_db_transactionObject



91
92
93
94
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 91

def commit_db_transaction
  client.commit_transaction(secret_arn: secret_arn, resource_arn: resource_arn, transaction_id: @current_transaction.transaction_id)
  @current_transaction = nil
end

#exec_rollback_db_transactionObject



96
97
98
99
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 96

def exec_rollback_db_transaction
  client.rollback_transaction(secret_arn: secret_arn, resource_arn: resource_arn, transaction_id: @current_transaction.transaction_id)
  @current_transaction = nil
end

#last_idObject



77
78
79
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 77

def last_id
  @last_result.generated_fields.first.values.compact.first
end

#pingObject



61
62
63
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 61

def ping
  query('SELECT 1')
end

#query(sql, **query_options) ⇒ Object



57
58
59
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 57

def query(sql, **query_options)
  _query(sql, **@query_options.merge(query_options))
end

#server_infoObject



81
82
83
84
85
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 81

def server_info
  {
    version: query('SHOW VARIABLES LIKE "version";', as: :array).first.last
  }
end