@@ -324,7 +324,8 @@ After you have set up your database, run an SQL query from within your Worker.
3243242 . Clear the content of ` index.ts ` .
3253253 . Paste the following code snippet into your ` index.ts ` file:
326326
327- <TypeScriptExample filename = " index.ts" >
327+ <Tabs syncKey = " workersExamples" >
328+ <TypeScriptExample filename = " index.ts" omitTabs = { true } >
328329 ``` typescript
329330 export interface Env {
330331 // If you set another name in the Wrangler config file for the value for 'binding',
@@ -353,6 +354,29 @@ After you have set up your database, run an SQL query from within your Worker.
353354 } satisfies ExportedHandler <Env >;
354355 ```
355356 </TypeScriptExample >
357+ <TabItem label = " Python" icon = " seti:python" >
358+ ``` python title="entry.py"
359+ from workers import Response, WorkerEntrypoint
360+ from urllib.parse import urlparse
361+
362+ class Default (WorkerEntrypoint ):
363+ async def fetch (self , request ):
364+ pathname = urlparse(request.url).path
365+ if pathname == " /api/beverages" :
366+ query = (
367+ await self .env.DB .prepare(
368+ " SELECT * FROM Customers WHERE CompanyName = ?" ,
369+ )
370+ .bind(" Bs Beverages" )
371+ .run()
372+ )
373+ return Response.json(query.results)
374+ return Response(
375+ " Call /api/beverages to see everyone who works at Bs Beverages"
376+ )
377+ ```
378+ </TabItem >
379+ </Tabs >
356380
357381 In the code above, you:
358382
0 commit comments