You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/d1/best-practices/query-d1.mdx
+28-24Lines changed: 28 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ D1 understands SQLite semantics, which allows you to query a database using SQL
19
19
20
20
### Use foreign key relationships
21
21
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.
23
23
24
24
```sql
25
25
CREATETABLEusers (
@@ -49,15 +49,16 @@ Given the following JSON object (`type:blob`) in a column named `sensor_reading`
49
49
50
50
```json
51
51
{
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
+
}
59
59
}
60
60
```
61
+
61
62
```sql
62
63
-- Extract the temperature value
63
64
SELECT json_extract(sensor_reading, '$.measurement.temp_f')-- returns "77.4" as TEXT
@@ -77,22 +78,24 @@ This requires you to:
77
78
78
79
```js title="index.js"
79
80
exportdefault {
80
-
asyncfetch(request, env) {
81
-
const {pathname} =newURL(request.url);
82
-
constcompanyName1=`Bs Beverages`;
83
-
constcompanyName2=`Around the Horn`;
84
-
conststmt=env.DB.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
0 commit comments