Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum the new setter with the data #69

Open
thadeubrito opened this issue Feb 3, 2016 · 1 comment
Open

Sum the new setter with the data #69

thadeubrito opened this issue Feb 3, 2016 · 1 comment

Comments

@thadeubrito
Copy link

Hello, I don't know if is possible do it using this gem, it is the case:

connection = Mysql2::Client.new([...])
Upsert.batch(connection, :pets) do |upsert|
  # N times...
  upsert.row({:name => 'product1'}, :count => 2)
  upsert.row({:name => 'product2'}, :count => 10)
end

I don't wanna only update the count attribute, if the product1 has a count: 1 in the database, I wanna sum the database value with the new value. In this case product1.count became 3(2+1).

Is it possible? Thanks all

@evadne
Copy link
Contributor

evadne commented Mar 22, 2016

Use a trigger? You can sum from OLD and NEW rows this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants