Module: EmSequelAsync::SequelExtensions::Model::ClassMethods

Defined in:
lib/em-sequel-async/sequel_extensions.rb

Instance Method Summary collapse

Instance Method Details

#async_lookup(args) ⇒ Object

Async version of Model#[]



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/em-sequel-async/sequel_extensions.rb', line 202

def async_lookup(args)
  unless (Hash === args)
    args = primary_key_hash(args)
  end

  dataset.where(args).limit(1).async_all do |rows|
    yield(rows.any? ? rows.first : nil)
  end

  return
end

#async_multi_insert_ignore_hash(hashes) ⇒ Object

This differs from async_multi_insert_ignore in that it takes an array of hashes rather than a series of arrays. The columns are automatically determined based on the keys of first hash provided.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/em-sequel-async/sequel_extensions.rb', line 183

def async_multi_insert_ignore_hash(hashes)
  if (hashes.empty?)
    yield if (block_given?)

    return
  end

  columns = hashes.first.keys

  insertions = hashes.collect do |row|
    columns.collect { |c| row[c] }
  end

  async_multi_insert_ignore(columns, insertions) do |n|
    yield(n) if (block_given?)
  end
end