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

D1 API: Re-attempting changes to .run behind a compat_date flag #1890

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/cloudflare/internal/test/d1/d1-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const test_d1_api = test(async (DB) => {
land_based BOOLEAN
);`
).run(),
{ success: true, meta: anything }
{ success: true, results: [],meta: anything }
)

await itShould(
Expand All @@ -92,13 +92,13 @@ export const test_d1_api = test(async (DB) => {
await itShould(
'have no results for .run()',
() => DB.prepare(`SELECT * FROM users;`).run(),
{ success: true, meta: anything }
{ success: true, results: [], meta: anything }
)

await itShould(
'delete no rows ok',
() => DB.prepare(`DELETE FROM users;`).run(),
{ success: true, meta: anything }
{ success: true, results: [], meta: anything }
)

await itShould(
Expand Down Expand Up @@ -137,7 +137,7 @@ export const test_d1_api = test(async (DB) => {
await itShould(
'delete two rows ok',
() => DB.prepare(`DELETE FROM users;`).run(),
{ success: true, meta: anything }
{ success: true, results: [], meta: anything }
)

// In an earlier implementation, .run() called a different endpoint that threw on RETURNING clauses.
Expand All @@ -153,6 +153,22 @@ export const test_d1_api = test(async (DB) => {
`
).run(),
{
results: [
{
user_id: 1,
name: 'Albert Ross',
home: 'sky',
features: 'wingspan',
land_based: 0,
},
{
user_id: 2,
name: 'Al Dente',
home: 'bowl',
features: 'mouthfeel',
land_based: 1,
},
],
success: true,
meta: anything,
}
Expand Down Expand Up @@ -339,7 +355,7 @@ export const test_d1_api = test(async (DB) => {
DB.prepare(`SELECT count(1) as count FROM users WHERE land_based = ?`)
.bind(2)
.first('count'),
0,
0
)

await itShould(
Expand Down
5 changes: 3 additions & 2 deletions src/cloudflare/internal/test/d1/d1-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export class D1MockDO {
const rawResults = Array.from(stmt.raw())

const results =
resultsFormat === 'NONE'
// TODO: restore 'NONE' behaviour behind compat flag
/*resultsFormat === 'NONE'
? undefined
: resultsFormat === 'ROWS_AND_COLUMNS'
: */resultsFormat === 'ROWS_AND_COLUMNS'
? { columns: columnNames, rows: rawResults }
: rawResults.map((row) =>
Object.fromEntries(columnNames.map((c, i) => [c, row[i]]))
Expand Down