tursodatabase / tursodatabase/libsql
Batch scopes
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 17.2k
- Forks
- 531
- Avg merge
- 1h 12m
- Merged PRs (30d)
- 1
Description
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);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the existing connection and transaction APIs around the proposed conn.batch() entry point, then compare how Batch, BatchHandle, and BatchResponse would fit the current API. Done means parameterized executes and queries can be collected, committed together, and queried afterward through returned handles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sqlite
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100