Skip to content

Commit 5bdfe59

Browse files
Initial commit
1 parent 5913780 commit 5bdfe59

File tree

22 files changed

+3361
-0
lines changed

22 files changed

+3361
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export interface Env {
2+
// If you set another name in wrangler.toml as the value for 'binding',
3+
// replace "DB" with the variable name you defined.
4+
DB: D1Database;
5+
}
6+
7+
export default {
8+
async fetch(request, env): Promise<Response> {
9+
const { pathname } = new URL(request.url);
10+
11+
if (pathname === "/api/companies") {
12+
// If you did not use `DB` as your binding name, change it here
13+
const { results } = await env.DB.prepare(
14+
"SELECT EmployeeID, EmployeeName, CompanyName FROM Employees JOIN Companies ON Employees.CompanyID = Companies.CompanyID;"
15+
)
16+
17+
.all();
18+
return Response.json(results);
19+
}
20+
21+
return new Response(
22+
"Call /api/companies to view a joined list of all employees from the Employees table along with the name of the company they work for from the Companies table"
23+
);
24+
},
25+
} satisfies ExportedHandler<Env>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DROP TABLE IF EXISTS Companies;
2+
CREATE TABLE IF NOT EXISTS Companies (CompanyID INTEGER PRIMARY KEY, CompanyName TEXT);
3+
INSERT INTO Companies (CompanyID, CompanyName) VALUES (1, 'Soda Co.'), (2, 'TV Media'), (3,'Software Co.');
4+
5+
DROP TABLE IF EXISTS Employees;
6+
CREATE TABLE IF NOT EXISTS Employees (EmployeeID INTEGER PRIMARY KEY, EmployeeName TEXT, CompanyID INTEGER, FOREIGN KEY (CompanyID) REFERENCES Companies(CompanyID));
7+
INSERT INTO Employees (EmployeeID, EmployeeName, CompanyID) VALUES (1, 'Olivia Johnson', 2), (2, 'Noah Jones', 3), (3, 'James Smith', 1), (4, 'Sophia Martinez', 2);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
async fetch(request, env, ctx) {
3+
(pathname === "/success") {
4+
return new Response('I have completed my first Cloudflare CLI Tutor challenge!');
5+
}
6+
{
7+
return new ('Hello world!');
8+
},
9+
};

media/stereo.jpg

203 KB
Loading

0 commit comments

Comments
 (0)