hiropon
hiropon

Reputation: 1802

How to do "bulk insert" with Hanami when I use migration

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 ?

Upvotes: 1

Views: 325

Answers (1)

hiropon
hiropon

Reputation: 1802

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"}])

Upvotes: 3

Related Questions