1

Recently I have tried using Hanami, Ruby framework. I would like to execute migration with "bulk insert".

I checked following issue discussion.

But, I don't understand how to call ROM object from Hanami. Would you please explain how to do that and any web site to refer ?

hiropon
  • 1,675
  • 2
  • 18
  • 41

1 Answers1

3

Finally I have realized meaning of code.

At first, I wrote bulk_insert as instance method.

  • somes represents SQL table's name, I could use this with symbol

Repository sample

class SomeRepository < Hanami::Repository
  def bulk_insert(data)
    command(:create, somes, use: [:timestamps], result: :many).call(data)
  end
end

Bulk insert sample

# we can pass array of hash
SomeRepository.new.bulk_insert(some_array)
SomeRepository.new.bulk_insert([{name: "sample1"}, {name: "sample2"}, {name: "sample3"}])
hiropon
  • 1,675
  • 2
  • 18
  • 41