D1 batch types: preserve heterogeneous result tuples
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
The issue points to both batch declarations in types/defines/d1.d.ts, including the current Promise<D1Result<T>[]> return type at line 65. Read the overloads for D1Database.batch and D1DatabaseSession.batch, then check the workers-types test or type-check entry point for declaration tests. Done means tuple inputs infer the corresponding result type at each position while the existing homogeneous array overload still works.
Written by the indexing model from the issue text.
Description
D1Database.batch and D1DatabaseSession.batch apply one result type to every statement. Callers must use unions or casts when a batch returns different row shapes.
Reproduce with workers-types 5.20261117.1:
type User = {name: string};
type Count = {n: number};
declare const db: D1Database;
const result = await db.batch<User | Count>([
db.prepare("SELECT 'Ada' AS name"),
db.prepare('SELECT 1 AS n')
]);
result[0].results[0].name;
// TS2339: Property 'name' does not exist on type 'User | Count'
Both declarations currently return Promise<D1Result[]>.
Requested: a tuple-aware overload so callers can specify the row type at each statement position and receive [D1Result<User>, D1Result<Count>]. Preserve the current homogeneous array overload.
This is a declaration improvement; the SQL batch executes normally. No runtime change is requested.
- Dominant language
- C++
- Stars
- 9.3k
- Forks
- 845
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 558
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from cloudflare/workerd
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
cloudflare/workerd#8963 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cloudflare/workerd#8807 ·
Maintainers usually reply within 1 day
-
D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newlinePossibly taken @Jeremiah-D claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
cloudflare/workerd#8678 ·
Maintainers usually reply within 1 day
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded propertyPossibly taken @itsrayeedscodespace claimed this 19 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudflare/workerd#8290 ·
Maintainers usually reply within 1 day
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunkMay be free again @oliarmak-web claimed this 19 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/workerd#8279 · 1 comment ·
Maintainers usually reply within 1 day
All issues in cloudflare/workerd
Similar issues
-
Android Bug Core Drape
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
organicmaps/organicmaps#14449 ·
Maintainers usually reply within 1 day
-
comp-codecs
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ClickHouse/ClickHouse#135159 ·
Maintainers usually reply within 1 day
-
difficulty:easy func:python os:windows prio:high type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NatronGitHub/Natron#2029 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ardazishvili/Sota#114 ·
Maintainers usually reply within 1 day
-
`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a pointOpenNeeds: Triage :mag:
Difficulty 1/5 Under an hour Newbie friendliness 82/100
react/react-native#60349 ·
Maintainers usually reply within 1 day