Class: ActiveRecord::ConnectionAdapters::SQLite3WasmAdapter

Inherits:
SQLite3Adapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb

Defined Under Namespace

Classes: ExternalInterface, JSBinary, Statement

Constant Summary collapse

TYPE_MAP =

Re-initialize type map to include JSBinary

Type::TypeMap.new.tap { |m| initialize_type_map(m) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSQLite3WasmAdapter

Returns a new instance of SQLite3WasmAdapter.



192
193
194
195
196
197
198
199
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 192

def initialize(...)
  AbstractAdapter.instance_method(:initialize).bind_call(self, ...)

  @prepared_statements = false
  @memory_database = false
  @connection_parameters = @config.merge(database: @config[:database].to_s, results_as_hash: true)
  @use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
end

Instance Attribute Details

#external_interfaceObject (readonly)

Returns the value of attribute external_interface.



190
191
192
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 190

def external_interface
  @external_interface
end

Class Method Details

.database_exists?(config) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 174

def database_exists?(config)
  true
end

.new_client(config) ⇒ Object



178
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 178

def new_client(config) = ExternalInterface.new(config)

Instance Method Details

#database_exists?Boolean

Returns:

  • (Boolean)


201
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 201

def database_exists? = true

#database_versionObject



203
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 203

def database_version = SQLite3Adapter::Version.new("3.45.1")

#perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false) ⇒ Object

Rails 8 interface



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/active_record/connection_adapters/sqlite3_wasm_adapter.rb', line 206

def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false)
  if batch
    raw_connection.execute_batch2(sql)
  elsif prepare
    raise NotImplementedError, "sqlite3_wasm prepared statements are not implemented yet"
  else
    stmt = raw_connection.prepare(sql)
    result =
      if stmt.column_count.zero?
        ActiveRecord::Result.empty
      else
        ActiveRecord::Result.new(stmt.columns, stmt.to_a)
      end
  end

  @last_affected_rows = raw_connection.changes
  verified!

  notification_payload[:row_count] = result&.length || 0
  result
end