@@ -25,3 +25,78 @@ d1_databases = [
2525```
2626
2727In 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 have multiple environments in your D1 binding, your ` wrangler.toml ` may look like the following:
32+
33+ ``` toml
34+ [[env .abc ]]
35+ binding = " DB"
36+ database_name = " DATABASE_NAME"
37+ database_id = " DATABASE_ID"
38+ ```
39+
40+ In the above configuration:
41+
42+ - ` [[something.abc]] ` creates an object ` something ` with a property ` abc ` (which is an object itself).
43+ - Any property below the line in the form ` <key> = <value> ` is a property of the ` abc ` object.
44+
45+ Therefore, the above binding is equivalent to:
46+
47+ ``` json
48+ {
49+ "something" : {
50+ "abc" : [
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+ "staging" : {
82+ "d1_databases" : [
83+ {
84+ "binding" : " BINDING_NAME_1" ,
85+ "database_id" : " PRODUCTION_DATABASE_1" ,
86+ "database_name" : " UUID_1"
87+ }
88+ ]
89+ },
90+ "production" : {
91+ "d1_databases" : [
92+ {
93+ "binding" : " BINDING_NAME_2" ,
94+ "database_name" : " DATABASE_NAME_2" ,
95+ "database_id" : " UUID_2"
96+ }
97+ ]
98+ }
99+ }
100+ }
101+ }
102+ ```
0 commit comments