This PR streamlines the different query APIs, adds value transforms and introduces a new argv mode:
transform = ->(h) { MyModel.new(h) }
db.query(transform, 'select * from foo')
transform = ->(a, b, c) { { a: a, b: b, c: JSON.parse(c) } }
db.query_argv(transform, 'select a, b, c from foo')
# transforms on prepared queries
q = db.prepare('select * from foo') { |h| MyModel.new(h) }
q.to_a #=> transformed rows
q = db.prepare_argv('select a, b, c from foo') { |a, b, c| { a: a, b: b, c: JSON.parse(c) } }
q.to_a #=> transformed rows
The #query_argv method can be significantly faster than #query_ary, but more benchmarks are needed. All in all the transforms in themselves don't really change much in terms of performance, it's more of a convenience.
This PR streamlines the different query APIs, adds value transforms and introduces a new
argv
mode:The
#query_argv
method can be significantly faster than#query_ary
, but more benchmarks are needed. All in all the transforms in themselves don't really change much in terms of performance, it's more of a convenience.