# upsert gem 使用 [upsert gem](https://github.com/seamusabshere/upsert) ### 情境: 每天更新某個表,每次可能更新的數量眾多 ### Upsert row ``` upsert = Upsert.new(connection, table_name) data.each do |datum| upsert.row({ selector... }, { setter... }) end ``` ### Upsesrt batch ``` Upsert.batch(connection, :table_name) do |upsert| data.each do |datum| upsert.row({ selector... }, { setter... }) end end ``` ### BenchMark 全 insert 的例子 (683 rows) ``` user system total real upsert 0.150539 0.053402 0.203941 ( 0.617650) upsert batch 0.134048 0.041398 0.175446 ( 0.868362) SQL find/update 1.176058 0.148097 1.324155 ( 1.682030) ``` 全 update 的例子 (683 rows) ``` user system total real upsert 0.146811 0.050948 0.197759 ( 0.895740) upsert batch 0.128561 0.040608 0.169169 ( 0.883774) SQL find/update 1.146444 0.143768 1.290212 ( 1.628095) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up