Skip to content

Commit

Permalink
Add a test for Workers SDK issue
Browse files Browse the repository at this point in the history
The issue: cloudflare/workers-sdk#3160

The test is passing and it is proof of the expected behavior that Workers SDK doesn't match.
  • Loading branch information
kossnocorp committed May 25, 2024
1 parent 1d89f3b commit 1bfb838
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/cloudflare/internal/test/d1/d1-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,46 @@ export const test_d1_api = test(async (DB) => {
meta: meta({ rows_read: 3, rows_written: 0 }),
}
)

await itShould(
'properly JOIN columns with the same name',
() =>
DB.batch([
DB.prepare(
`CREATE TABLE organizations
(
id INTEGER PRIMARY KEY,
name TEXT
);`
),
DB.prepare(
`CREATE TABLE projects (
id INTEGER PRIMARY KEY,
name TEXT,
organization_id INTEGER,
FOREIGN KEY (organization_id) REFERENCES organizations(id)
);`
)
]),
[
{ success: true, results: [], meta: anything },
{ success: true, results: [], meta: anything }
],
() =>
DB.batch([
DB.prepare(`INSERT INTO organizations (id, name) VALUES (1, 'Cloudflare');`),
DB.prepare(`INSERT INTO projects (id, name, organization_id) VALUES (1, 'Cloudflare', 1);`),
]),
[
{ success: true, results: [], meta: anything },
{ success: true, results: [], meta: anything }
],
() =>
DB.prepare(
`SELECT projects.name, organizations.name
FROM projects
JOIN organizations ON projects.organization_id = organizations.id;`
).raw(),
[['Cloudflare', 'Cloudflare']]
)
})

0 comments on commit 1bfb838

Please sign in to comment.