File tree Expand file tree Collapse file tree 2 files changed +515
-1
lines changed
src/test/documentation_examples Expand file tree Collapse file tree 2 files changed +515
-1
lines changed Original file line number Diff line number Diff line change
1
+ use bson:: { doc, DateTime } ;
2
+
3
+ use crate :: Database ;
4
+
5
+ use super :: GenericResult ;
6
+
7
+ pub ( crate ) async fn populate ( db : & Database ) -> GenericResult < ( ) > {
8
+ let date_20180208 = DateTime :: parse_rfc3339_str ( "2018-02-08T09:00:00.000Z" ) ?;
9
+ let date_20180109 = DateTime :: parse_rfc3339_str ( "2018-01-09T07:12:00.000Z" ) ?;
10
+ let date_20180127 = DateTime :: parse_rfc3339_str ( "2018-01-27T09:13:00.000Z" ) ?;
11
+ let date_20180203 = DateTime :: parse_rfc3339_str ( "2018-02-03T07:58:00.000Z" ) ?;
12
+ let date_20180205 = DateTime :: parse_rfc3339_str ( "2018-02-05T06:03:00.000Z" ) ?;
13
+ let date_20180111 = DateTime :: parse_rfc3339_str ( "2018-01-11T07:15:00.000Z" ) ?;
14
+
15
+ db. collection ( "sales" )
16
+ . insert_many (
17
+ vec ! [
18
+ doc! {
19
+ "date" : date_20180208,
20
+ "items" : [
21
+ doc! {
22
+ "fruit" : "kiwi" ,
23
+ "quantity" : 2 ,
24
+ "price" : 0.5 ,
25
+ } ,
26
+ doc! {
27
+ "fruit" : "apple" ,
28
+ "quantity" : 1 ,
29
+ "price" : 1.0 ,
30
+ } ,
31
+ ] ,
32
+ } ,
33
+ doc! {
34
+ "date" : date_20180109,
35
+ "items" : [
36
+ doc! {
37
+ "fruit" : "banana" ,
38
+ "quantity" : 8 ,
39
+ "price" : 1.0 ,
40
+ } ,
41
+ doc! {
42
+ "fruit" : "apple" ,
43
+ "quantity" : 1 ,
44
+ "price" : 1.0 ,
45
+ } ,
46
+ doc! {
47
+ "fruit" : "papaya" ,
48
+ "quantity" : 1 ,
49
+ "price" : 4.0 ,
50
+ } ,
51
+ ] ,
52
+ } ,
53
+ doc! {
54
+ "date" : date_20180127,
55
+ "items" : [
56
+ doc! {
57
+ "fruit" : "banana" ,
58
+ "quantity" : 1 ,
59
+ "price" : 1.0 ,
60
+ } ,
61
+ ] ,
62
+ } ,
63
+ doc! {
64
+ "date" : date_20180203,
65
+ "items" : [
66
+ doc! {
67
+ "fruit" : "banana" ,
68
+ "quantity" : 1 ,
69
+ "price" : 1.0 ,
70
+ } ,
71
+ ] ,
72
+ } ,
73
+ doc! {
74
+ "date" : date_20180205,
75
+ "items" : [
76
+ doc! {
77
+ "fruit" : "banana" ,
78
+ "quantity" : 1 ,
79
+ "price" : 1.0 ,
80
+ } ,
81
+ doc! {
82
+ "fruit" : "mango" ,
83
+ "quantity" : 2 ,
84
+ "price" : 2.0 ,
85
+ } ,
86
+ doc! {
87
+ "fruit" : "apple" ,
88
+ "quantity" : 1 ,
89
+ "price" : 1.0 ,
90
+ } ,
91
+ ] ,
92
+ } ,
93
+ doc! {
94
+ "date" : date_20180111,
95
+ "items" : [
96
+ doc! {
97
+ "fruit" : "banana" ,
98
+ "quantity" : 1 ,
99
+ "price" : 1.0 ,
100
+ } ,
101
+ doc! {
102
+ "fruit" : "apple" ,
103
+ "quantity" : 1 ,
104
+ "price" : 1.0 ,
105
+ } ,
106
+ doc! {
107
+ "fruit" : "papaya" ,
108
+ "quantity" : 3 ,
109
+ "price" : 4.0 ,
110
+ } ,
111
+ ] ,
112
+ } ,
113
+ ] ,
114
+ None ,
115
+ )
116
+ . await ?;
117
+ db. collection ( "airlines" )
118
+ . insert_many (
119
+ vec ! [
120
+ doc! {
121
+ "airline" : 17 ,
122
+ "name" : "Air Canada" ,
123
+ "alias" : "AC" ,
124
+ "iata" : "ACA" ,
125
+ "icao" : "AIR CANADA" ,
126
+ "active" : "Y" ,
127
+ "country" : "Canada" ,
128
+ "base" : "TAL" ,
129
+ } ,
130
+ doc! {
131
+ "airline" : 18 ,
132
+ "name" : "Turkish Airlines" ,
133
+ "alias" : "YK" ,
134
+ "iata" : "TRK" ,
135
+ "icao" : "TURKISH" ,
136
+ "active" : "Y" ,
137
+ "country" : "Turkey" ,
138
+ "base" : "AET" ,
139
+ } ,
140
+ doc! {
141
+ "airline" : 22 ,
142
+ "name" : "Saudia" ,
143
+ "alias" : "SV" ,
144
+ "iata" : "SVA" ,
145
+ "icao" : "SAUDIA" ,
146
+ "active" : "Y" ,
147
+ "country" : "Saudi Arabia" ,
148
+ "base" : "JSU" ,
149
+ } ,
150
+ doc! {
151
+ "airline" : 29 ,
152
+ "name" : "Finnair" ,
153
+ "alias" : "AY" ,
154
+ "iata" : "FIN" ,
155
+ "icao" : "FINNAIR" ,
156
+ "active" : "Y" ,
157
+ "country" : "Finland" ,
158
+ "base" : "JMZ" ,
159
+ } ,
160
+ doc! {
161
+ "airline" : 34 ,
162
+ "name" : "Afric'air Express" ,
163
+ "alias" : "" ,
164
+ "iata" : "AAX" ,
165
+ "icao" : "AFREX" ,
166
+ "active" : "N" ,
167
+ "country" : "Ivory Coast" ,
168
+ "base" : "LOK" ,
169
+ } ,
170
+ doc! {
171
+ "airline" : 37 ,
172
+ "name" : "Artem-Avia" ,
173
+ "alias" : "" ,
174
+ "iata" : "ABA" ,
175
+ "icao" : "ARTEM-AVIA" ,
176
+ "active" : "N" ,
177
+ "country" : "Ukraine" ,
178
+ "base" : "JBR" ,
179
+ } ,
180
+ doc! {
181
+ "airline" : 38 ,
182
+ "name" : "Lufthansa" ,
183
+ "alias" : "LH" ,
184
+ "iata" : "DLH" ,
185
+ "icao" : "LUFTHANSA" ,
186
+ "active" : "Y" ,
187
+ "country" : "Germany" ,
188
+ "base" : "CYS" ,
189
+ } ,
190
+ ] ,
191
+ None ,
192
+ )
193
+ . await ?;
194
+ db. collection ( "air_alliances" )
195
+ . insert_many (
196
+ vec ! [
197
+ doc! {
198
+ "name" : "Star Alliance" ,
199
+ "airlines" : [
200
+ "Air Canada" ,
201
+ "Avianca" ,
202
+ "Air China" ,
203
+ "Air New Zealand" ,
204
+ "Asiana Airlines" ,
205
+ "Brussels Airlines" ,
206
+ "Copa Airlines" ,
207
+ "Croatia Airlines" ,
208
+ "EgyptAir" ,
209
+ "TAP Portugal" ,
210
+ "United Airlines" ,
211
+ "Turkish Airlines" ,
212
+ "Swiss International Air Lines" ,
213
+ "Lufthansa" ,
214
+ ] ,
215
+ } ,
216
+ doc! {
217
+ "name" : "SkyTeam" ,
218
+ "airlines" : [
219
+ "Aerolinias Argentinas" ,
220
+ "Aeromexico" ,
221
+ "Air Europa" ,
222
+ "Air France" ,
223
+ "Alitalia" ,
224
+ "Delta Air Lines" ,
225
+ "Garuda Indonesia" ,
226
+ "Kenya Airways" ,
227
+ "KLM" ,
228
+ "Korean Air" ,
229
+ "Middle East Airlines" ,
230
+ "Saudia" ,
231
+ ] ,
232
+ } ,
233
+ doc! {
234
+ "name" : "OneWorld" ,
235
+ "airlines" : [
236
+ "Air Berlin" ,
237
+ "American Airlines" ,
238
+ "British Airways" ,
239
+ "Cathay Pacific" ,
240
+ "Finnair" ,
241
+ "Iberia Airlines" ,
242
+ "Japan Airlines" ,
243
+ "LATAM Chile" ,
244
+ "LATAM Brasil" ,
245
+ "Malasya Airlines" ,
246
+ "Canadian Airlines" ,
247
+ ] ,
248
+ } ,
249
+ ] ,
250
+ None ,
251
+ )
252
+ . await ?;
253
+
254
+ Ok ( ( ) )
255
+ }
You can’t perform that action at this time.
0 commit comments