File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,15 @@ private def random_world
2222 {id: id, randomNumber: random_number}
2323end
2424
25- private def set_world (world )
26- APPDB .exec(" UPDATE world SET randomNumber = $1 WHERE id = $2" , world[:randomNumber ], world[:id ])
27- world
25+ private def update_worlds (worlds )
26+ ids = [] of Int32
27+ sql = " UPDATE world SET randomnumber = CASE id "
28+ worlds.each do |world |
29+ sql += " when #{ world[:id ] } then #{ world[:randomNumber ] } "
30+ ids << world[:id ]
31+ end
32+ sql += " ELSE randomnumber END WHERE id IN ( #{ ids.join(',' ) } )"
33+ APPDB .exec(sql)
2834end
2935
3036private def fortunes
123129# Postgres Test 5: Database Updates
124130get " /updates" do |env |
125131 updated = (1 ..sanitized_query_count(env)).map do
126- set_world( {id: random_world[:id ], randomNumber: rand(1 ..ID_MAXIMUM )})
132+ {id: random_world[:id ], randomNumber: rand(1 ..ID_MAXIMUM )}
127133 end
128134
135+ update_worlds(updated)
136+
129137 env.response.content_type = CONTENT ::JSON
130138 updated.to_json
131139end
You can’t perform that action at this time.
0 commit comments