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
"SELECT Id, CustomerName, OrderDate FROM [Order] ORDER BY ShippedDate DESC LIMIT 100",
33
+
"SELECT Id, CustomerName, OrderDate FROM [Order] ORDER BY ShippedDate DESC LIMIT 100",
38
34
).run<OrderRow>();
39
35
```
40
36
41
37
## Type conversion
42
38
43
-
D1 automatically converts supported JavaScript (including TypeScript) types passed as parameters via the Workers Binding API to their associated D1 types. The type conversion is as follows:
39
+
D1 automatically converts supported JavaScript (including TypeScript) types passed as parameters via the Workers Binding API to their associated D1 types <sup>1</sup>.
40
+
This conversion is permanent and one-way only, meaning that when reading the written values back in your code you will get the converted values and not the originally inserted values.
41
+
42
+
Sidenote: We recommend using [STRICT tables](https://www.sqlite.org/stricttables.html) in your SQL schema to avoid issues with mismatched types actually stored in your database compared to what your schema defines.
<sup>5</sup> Queries with `undefined` values will return a `D1_TYPE_ERROR`.
74
+
63
75
## API playground
64
76
65
77
The D1 Worker Binding API playground is an `index.js` file where you can test each of the documented Worker Binding APIs for D1. The file builds from the end-state of the [Get started](/d1/get-started/#write-queries-within-your-worker) code.
@@ -80,55 +92,51 @@ Replace the contents of your `index.js` file with the code below to view the eff
80
92
```js
81
93
exportdefault {
82
94
asyncfetch(request, env) {
83
-
const { pathname } =newURL(request.url);
84
-
// if (pathname === "/api/beverages") {
85
-
// // If you did not use `DB` as your binding name, change it here
86
-
// const { results } = await env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?",).bind("Bs Beverages").all();
87
-
// return Response.json(results);
88
-
// }
95
+
const { pathname } =newURL(request.url);
96
+
// if (pathname === "/api/beverages") {
97
+
// // If you did not use `DB` as your binding name, change it here
98
+
// const { results } = await env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?",).bind("Bs Beverages").all();
99
+
// return Response.json(results);
100
+
// }
89
101
constcompanyName1=`Bs Beverages`;
90
102
constcompanyName2=`Around the Horn`;
91
103
conststmt=env.DB.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
92
104
conststmtMulti=env.DB.prepare(`SELECT * FROM Customers; SELECT * FROM Customers WHERE CompanyName = ?`);
93
105
constsession=env.DB.withSession("first-primary")
94
106
constsessionStmt=session.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
0 commit comments