new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle · SQLite · all subjects

batch-api

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Batch API support in SQLite drivers

Drizzle supports running SQL statements in a batch with SQLite-compatible libSQL and Cloudflare D1 drivers.

libSQL Batch API definition

With the libSQL client library, a batch is one or more SQL statements executed in order in an implicit transaction. If all statements are successful, the transaction is committed. If any statement fails, the transaction is rolled back.

D1 Batch API definition

Batching in D1 sends multiple SQL statements inside a single call to the database. This can reduce latency from network round trips to D1.

db.batch() example with multiple query types

The batch API accepts an array of queries. Example: const batchResponse = await db.batch([db.insert(usersTable).values({ id: 1, name: 'John' }).returning({ id: usersTable.id }), db.update(usersTable).set({ name: 'Dan' }).where(eq(usersTable.id, 1)), db.query.usersTable.findMany({}), db.select().from(usersTable).where(eq(usersTable.id, 1)), db.select({ id: usersTable.id, invitedBy: usersTable.invitedBy }).from(usersTable)]);

libSQL batch response type

For libSQL driver, the batch response is a tuple array where each element corresponds to the result of each query in the batch. The first element from db.insert().returning() is { id: number }[], the second from db.update() is ResultSet, and subsequent selects return their respective row type arrays.

D1 batch response type

For D1 driver, the batch response is a tuple array where each element corresponds to the result of each query in the batch. The first element from db.insert().returning() is { id: number }[], the second from db.update() is D1Result, and subsequent selects return their respective row type arrays.

All query builders supported in db.batch()

The following query builders can be used inside db.batch(): db.all(), db.get(), db.values(), db.run(), db.execute(), db.query.<table>.findMany(), db.query.<table>.findFirst(), db.select(), db.update(), db.delete(), db.insert().

Give your agent this brain