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

Batch scopes #1757

Open
levydsa opened this issue Sep 26, 2024 · 0 comments
Open

Batch scopes #1757

levydsa opened this issue Sep 26, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@levydsa
Copy link
Contributor

levydsa commented Sep 26, 2024

Batch statements are quite limited in the current API. You can only execute
multiple queries without parameters. And if need to execute a list of
statements, you would need to join those strings separated by ";".

Proposal: Create a batch object that acts like regular connection or
transaction, and batch all executes and queries when you call .commit() on
that object. Rows can be accessed with a handle via a object returned by the
commit.

let batch: Batch = conn.batch();

batch.execute("create table if not exists test (i integer)", ())?;

for i in 0..10 {
    batch.execute("insert into test values (?)", params![i])?;
}

// You can't use the Rows from a query before it is batched. To prevent it,
// only give a handle to access rows with the BatchResponse. This should only
// be wrapper of a index (u32) that can only be returned by `.query()`.
let handle: BatchHandle = batch.query("select * from test", ())?;

let batch_res: BatchResponse = batch.commit()?; // Batch all statements

// batch.query/execute(...) cannot be called here, ownership is passed to `.commit()`

let rows = batch_res.get(handle);
@levydsa levydsa added the enhancement New feature or request label Sep 26, 2024
@levydsa levydsa self-assigned this Sep 26, 2024
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

No branches or pull requests

1 participant