Skip to content

Commit 37f5d4f

Browse files
remove all and and repetitions
1 parent 41fa7a5 commit 37f5d4f

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/content/docs/d1/best-practices/query-d1.mdx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ D1 understands SQLite semantics, which allows you to query a database using SQL
1919

2020
### Use foreign key relationships
2121

22-
When using SQL with D1, you may wish to define and and enforce foreign key constraints across tables in a database. Foreign key constraints allow you to enforce relationships across tables, or prevent you from deleting rows that reference rows in other tables. An example of a foreign key relationship is shown below.
22+
When using SQL with D1, you may wish to define and enforce foreign key constraints across tables in a database. Foreign key constraints allow you to enforce relationships across tables, or prevent you from deleting rows that reference rows in other tables. An example of a foreign key relationship is shown below.
2323

2424
```sql
2525
CREATE TABLE users (
@@ -49,15 +49,16 @@ Given the following JSON object (`type:blob`) in a column named `sensor_reading`
4949

5050
```json
5151
{
52-
"measurement": {
53-
"temp_f": "77.4",
54-
"aqi": [21, 42, 58],
55-
"o3": [18, 500],
56-
"wind_mph": "13",
57-
"location": "US-NY"
58-
}
52+
"measurement": {
53+
"temp_f": "77.4",
54+
"aqi": [21, 42, 58],
55+
"o3": [18, 500],
56+
"wind_mph": "13",
57+
"location": "US-NY"
58+
}
5959
}
6060
```
61+
6162
```sql
6263
-- Extract the temperature value
6364
SELECT json_extract(sensor_reading, '$.measurement.temp_f')-- returns "77.4" as TEXT
@@ -77,22 +78,24 @@ This requires you to:
7778

7879
```js title="index.js"
7980
export default {
80-
async fetch(request, env) {
81-
const {pathname} = new URL(request.url);
82-
const companyName1 = `Bs Beverages`;
83-
const companyName2 = `Around the Horn`;
84-
const stmt = env.DB.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
85-
86-
if (pathname === `/RUN`) {
87-
const returnValue = await stmt.bind(companyName1).run();
88-
return Response.json(returnValue);
89-
}
90-
91-
return new Response(
92-
`Welcome to the D1 API Playground!
81+
async fetch(request, env) {
82+
const { pathname } = new URL(request.url);
83+
const companyName1 = `Bs Beverages`;
84+
const companyName2 = `Around the Horn`;
85+
const stmt = env.DB.prepare(
86+
`SELECT * FROM Customers WHERE CompanyName = ?`,
87+
);
88+
89+
if (pathname === `/RUN`) {
90+
const returnValue = await stmt.bind(companyName1).run();
91+
return Response.json(returnValue);
92+
}
93+
94+
return new Response(
95+
`Welcome to the D1 API Playground!
9396
\nChange the URL to test the various methods inside your index.js file.`,
94-
);
95-
},
97+
);
98+
},
9699
};
97100
```
98101

@@ -111,6 +114,7 @@ You can use Wrangler commands to query a D1 database. Note that Wrangler command
111114
```sh
112115
npx wrangler d1 execute prod-d1-tutorial --command="SELECT * FROM Customers"
113116
```
117+
114118
```sh output
115119
🌀 Mapping SQL input into an array of statements
116120
🌀 Executing on local database production-db-backend (<DATABASE_ID>) from .wrangler/state/v3/d1:
@@ -125,4 +129,4 @@ npx wrangler d1 execute prod-d1-tutorial --command="SELECT * FROM Customers"
125129
├────────────┼─────────────────────┼───────────────────┤
126130
│ 13 │ Bs Beverages │ Random Name │
127131
└────────────┴─────────────────────┴───────────────────┘
128-
```
132+
```

0 commit comments

Comments
 (0)