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
\nChange the URL to test the various methods inside your index.js file.`,
45
-
);
46
-
},
47
-
};
48
-
```
49
-
50
-
Refer to [Workers Binding API](/d1/worker-api/) for more information.
13
+
2. Using [D1 REST API](/api/operations/cloudflare-d1-create-database).
14
+
3. Using [D1 Wrangler commands](/d1/wrangler-commands/).
51
15
52
-
## Query D1 with SQL API
16
+
## Use SQL to query D1
53
17
54
18
D1 understands SQLite semantics, which allows you to query a database using SQL statements via Workers BindingAPI or REST API (including Wrangler commands). Refer to [D1 SQL API](/d1/sql-api/sql-statements/) to learn more about supported SQL statements.
55
19
@@ -101,6 +65,39 @@ SELECT json_extract(sensor_reading, '$.measurement.temp_f')-- returns "77.4" as
101
65
102
66
Refer to [Query JSON](/d1/sql-api/query-json/) to learn more about querying JSON objects.
103
67
68
+
## Query D1 with Workers Binding API
69
+
70
+
Workers Binding API primarily interacts with the data plane, and allows you to query your D1 database from your Worker.
71
+
72
+
This requires you to:
73
+
74
+
1. Bind your D1 database to your Worker.
75
+
2. Prepare a statement.
76
+
3. Run the statement.
77
+
78
+
```js title="index.js"
79
+
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