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

Add ability to batch execute queries from an Enumerable #47

Closed
noteflakes opened this issue Dec 25, 2023 · 0 comments · Fixed by #52
Closed

Add ability to batch execute queries from an Enumerable #47

noteflakes opened this issue Dec 25, 2023 · 0 comments · Fixed by #52
Labels
enhancement New feature or request

Comments

@noteflakes
Copy link
Contributor

Right now, the Extralite API includes a #execute_multi method, that takes an array and executes the same query repeatedly, taking its parameters from each array entry. This can be generalized into a #batch_execute method that can take an array, an enumerable, or a block. Some examples:

q = db.prepare('insert into foo (?, ?, ?)')

# Batch execute from an array (existing functionality)
data = [[1, 2, 3], [4, 5, 6]]
q.execute_batch(data)

# Batch execute from an Enumerable (by calling #each)
data = (1..3).lazy.map { |i| [i * 10, i * 20, i * 30] }
q.execute_batch(data)

# Batch execute from block
q.execute_batch do
  STDOUT << "Enter a number: "
  number = gets
  if number.empty?
    nil
  else
    number = number.to_i
    [number * 10, number * 20, number * 30]
  end
end

The #execute_multi method can first be an alias to #batch_execute, then be deprecated in a future release.

@noteflakes noteflakes added the enhancement New feature or request label Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant