class ActiveRecord::ConnectionAdapters::DataWorldAdapter

Public Instance Methods

exec_query(sql, name = nil, binds = [], prepare: false) click to toggle source
# File lib/active_record/connection_adapters/data_world_adapter.rb, line 53
def exec_query(sql, name = nil, binds = [], prepare: false)
  if preventing_writes? && write_query?(sql)
    raise ActiveRecord::ReadOnlyError, "Data.World is read-only, query not accepted: #{sql}"
  end

  type_casted_binds = type_casted_binds(binds)

  log(sql, name, binds, type_casted_binds) do
    raw = execute(sql_bind(sql, binds))
    cols = raw.dig(0, 'fields')&.map { |h| h['name'] }
    records = raw[1..-1].map(&:values)

    ActiveRecord::Result.new(cols, records)
  end
end
requires_reloading?() click to toggle source
# File lib/active_record/connection_adapters/data_world_adapter.rb, line 22
def requires_reloading?
  true
end
sql_bind(sql, binds) click to toggle source

do our best job binding the variables into the query

# File lib/active_record/connection_adapters/data_world_adapter.rb, line 70
def sql_bind(sql, binds)
  new_sql = sql.clone
  binds.each do |attribute|
    value = if attribute.value.is_a?(String)
      "'#{attribute.value}'"
    else
      attribute.value.to_s
    end

    new_sql = new_sql.sub('?', value)
  end
  new_sql
end
try_json(string) click to toggle source
# File lib/active_record/connection_adapters/data_world_adapter.rb, line 84
def try_json(string)
  JSON.parse(string)
rescue
  raise string
end
views() click to toggle source
# File lib/active_record/connection_adapters/data_world_adapter.rb, line 98
def views
  []
end

Protected Instance Methods

table_structure(table_name) click to toggle source
# File lib/active_record/connection_adapters/data_world_adapter.rb, line 111
def table_structure(table_name)
  columns = execute("SELECT * FROM TableColumns WHERE tableName = \"#{table_name}\"")[1..-1]
  raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if columns.empty?
  columns
end