Skip to content

Commit ffa4ed3

Browse files
Oxyjunlambrospetroupedrosousa
authored
[D1] Adding information on how wrangler.toml is structured behind the scenes. (#18145)
* Adding information on how wrangler.toml is structured behind the scenes. * Changing names to be more specific/relevant. * Fixing formatting. Clarifying wording. * Wording clarity * Update src/content/docs/d1/configuration/environments.mdx Co-authored-by: Lambros Petrou <[email protected]> * Replacing tabs with spaces. * Update src/content/docs/d1/configuration/environments.mdx Co-authored-by: Pedro Sousa <[email protected]> --------- Co-authored-by: Lambros Petrou <[email protected]> Co-authored-by: Pedro Sousa <[email protected]>
1 parent c6223f2 commit ffa4ed3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/content/docs/d1/configuration/environments.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,77 @@ d1_databases = [
2525
```
2626

2727
In the code above, the `staging` environment is using a different database (`DATABASE_NAME_1`) than the `production` environment (`DATABASE_NAME_2`).
28+
29+
## Anatomy of `wrangler.toml` file
30+
31+
If you need to specify different D1 databases for different environments, your `wrangler.toml` may contain bindings that resemble the following:
32+
33+
```toml
34+
[[production.d1_databases]]
35+
binding = "DB"
36+
database_name = "DATABASE_NAME"
37+
database_id = "DATABASE_ID"
38+
```
39+
40+
In the above configuration:
41+
42+
- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects, since you can create multiple D1 bindings in case you have more than one database.
43+
- Any property below the line in the form `<key> = <value>` is a property of an object within the `d1_databases` array.
44+
45+
Therefore, the above binding is equivalent to:
46+
47+
```json
48+
{
49+
"production": {
50+
"d1_databases": [
51+
{
52+
"binding": "DB",
53+
"database_name": "DATABASE_NAME",
54+
"database_id": "DATABASE_ID"
55+
}
56+
]
57+
}
58+
}
59+
```
60+
61+
### Example
62+
63+
```toml
64+
[[env.staging.d1_databases]]
65+
binding = "BINDING_NAME_1"
66+
database_name = "DATABASE_NAME_1"
67+
database_id = "UUID_1"
68+
69+
[[env.production.d1_databases]]
70+
binding = "BINDING_NAME_2"
71+
database_name = "DATABASE_NAME_2"
72+
database_id = "UUID_2"
73+
74+
```
75+
76+
The above is equivalent to the following structure in JSON:
77+
78+
```json
79+
{
80+
"env": {
81+
"production": {
82+
"d1_databases": [
83+
{
84+
"binding": "BINDING_NAME_2",
85+
"database_id": "UUID_2",
86+
"database_name": "DATABASE_NAME_2"
87+
}
88+
]
89+
},
90+
"staging": {
91+
"d1_databases": [
92+
{
93+
"binding": "BINDING_NAME_1",
94+
"database_id": "UUID_1",
95+
"database_name": "DATABASE_NAME_1"
96+
}
97+
]
98+
}
99+
}
100+
}
101+
```

0 commit comments

Comments
 (0)