@@ -4,41 +4,41 @@ function readValue() {
44 // [START rtdb_read_value]
55 // Get a database reference to our posts
66 const db = admin . database ( ) ;
7- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
7+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
88
99 // Attach an asynchronous callback to read the data at our posts reference
10- ref . on ( " value" , ( snapshot ) => {
10+ ref . on ( ' value' , ( snapshot ) => {
1111 console . log ( snapshot . val ( ) ) ;
1212 } , ( errorObject ) => {
13- console . log ( " The read failed: " + errorObject . name ) ;
13+ console . log ( ' The read failed: ' + errorObject . name ) ;
1414 } ) ;
1515 // [END rtdb_read_value]
1616}
1717
1818function childAdded ( ) {
1919 const db = admin . database ( ) ;
20- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
20+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
2121
2222 // [START rtdb_child_added]
2323 // Retrieve new posts as they are added to our database
24- ref . on ( " child_added" , ( snapshot , prevChildKey ) => {
24+ ref . on ( ' child_added' , ( snapshot , prevChildKey ) => {
2525 const newPost = snapshot . val ( ) ;
26- console . log ( " Author: " + newPost . author ) ;
27- console . log ( " Title: " + newPost . title ) ;
28- console . log ( " Previous Post ID: " + prevChildKey ) ;
26+ console . log ( ' Author: ' + newPost . author ) ;
27+ console . log ( ' Title: ' + newPost . title ) ;
28+ console . log ( ' Previous Post ID: ' + prevChildKey ) ;
2929 } ) ;
3030 // [END rtdb_child_added]
3131}
3232
3333function childChanged ( ) {
3434 const db = admin . database ( ) ;
35- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
35+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
3636
3737 // [START rtdb_child_changed]
3838 // Get the data on a post that has changed
39- ref . on ( " child_changed" , ( snapshot ) => {
39+ ref . on ( ' child_changed' , ( snapshot ) => {
4040 const changedPost = snapshot . val ( ) ;
41- console . log ( " The updated post title is " + changedPost . title ) ;
41+ console . log ( ' The updated post title is ' + changedPost . title ) ;
4242 } ) ;
4343 // [END rtdb_child_changed]
4444}
@@ -48,72 +48,72 @@ function childRemoved() {
4848
4949 // [START rtdb_child_removed]
5050 // Get a reference to our posts
51- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
51+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
5252
5353 // Get the data on a post that has been removed
54- ref . on ( " child_removed" , ( snapshot ) => {
54+ ref . on ( ' child_removed' , ( snapshot ) => {
5555 const deletedPost = snapshot . val ( ) ;
56- console . log ( " The blog post titled '" + deletedPost . title + "' has been deleted" ) ;
56+ console . log ( ' The blog post titled \'' + deletedPost . title + '\' has been deleted' ) ;
5757 } ) ;
5858 // [END rtdb_child_removed]
5959}
6060
6161function eventGuarantees ( ) {
6262 const db = admin . database ( ) ;
63- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
63+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
6464
6565 // [START rtdb_event_guarantees]
6666 let count = 0 ;
6767
68- ref . on ( " child_added" , ( snap ) => {
68+ ref . on ( ' child_added' , ( snap ) => {
6969 count ++ ;
70- console . log ( " added:" , snap . key ) ;
70+ console . log ( ' added:' , snap . key ) ;
7171 } ) ;
7272
7373 // length will always equal count, since snap.val() will include every child_added event
7474 // triggered before this point
75- ref . once ( " value" , ( snap ) => {
76- console . log ( " initial data loaded!" , snap . numChildren ( ) === count ) ;
75+ ref . once ( ' value' , ( snap ) => {
76+ console . log ( ' initial data loaded!' , snap . numChildren ( ) === count ) ;
7777 } ) ;
7878 // [END rtdb_event_guarantees]
7979}
8080
8181function detatchCallbacks ( ) {
8282 const db = admin . database ( ) ;
83- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
83+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
8484
8585 const originalCallback = ( ) => {
8686 // ...
87- }
87+ } ;
8888
8989 // [START rtdb_detach_callbacks]
90- ref . off ( " value" , originalCallback ) ;
90+ ref . off ( ' value' , originalCallback ) ;
9191 // [END rtdb_detach_callbacks]
9292}
9393
9494function detatchCallbacksContext ( ) {
9595 const db = admin . database ( ) ;
96- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
96+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
9797
9898 const originalCallback = ( ) => {
9999 // ...
100- }
100+ } ;
101101
102102 /** {@type any } */
103103 let ctx ;
104104
105105 // [START rtdb_detach_callbacks_context]
106- ref . off ( " value" , originalCallback , ctx ) ;
106+ ref . off ( ' value' , originalCallback , ctx ) ;
107107 // [END rtdb_detach_callbacks_context]
108108}
109109
110110function detachAllCallbacks ( ) {
111111 const db = admin . database ( ) ;
112- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
112+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
113113
114114 // [START rtdb_detach_all_callbacks]
115115 // Remove all value callbacks
116- ref . off ( " value" ) ;
116+ ref . off ( ' value' ) ;
117117
118118 // Remove all callbacks of any type
119119 ref . off ( ) ;
@@ -122,10 +122,10 @@ function detachAllCallbacks() {
122122
123123function readOnce ( ) {
124124 const db = admin . database ( ) ;
125- const ref = db . ref ( " server/saving-data/fireblog/posts" ) ;
125+ const ref = db . ref ( ' server/saving-data/fireblog/posts' ) ;
126126
127127 // [START rtdb_read_once]
128- ref . once ( " value" , ( data ) => {
128+ ref . once ( ' value' , ( data ) => {
129129 // do some stuff once
130130 } ) ;
131131 // [END rtdb_read_once]
@@ -135,10 +135,10 @@ function orderByChild() {
135135 const db = admin . database ( ) ;
136136
137137 // [START rtdb_order_by_child]
138- const ref = db . ref ( " dinosaurs" ) ;
138+ const ref = db . ref ( ' dinosaurs' ) ;
139139
140- ref . orderByChild ( " height" ) . on ( " child_added" , ( snapshot ) => {
141- console . log ( snapshot . key + " was " + snapshot . val ( ) . height + " meters tall" ) ;
140+ ref . orderByChild ( ' height' ) . on ( ' child_added' , ( snapshot ) => {
141+ console . log ( snapshot . key + ' was ' + snapshot . val ( ) . height + ' meters tall' ) ;
142142 } ) ;
143143 // [END rtdb_order_by_child]
144144}
@@ -147,9 +147,9 @@ function orderByChildNested() {
147147 const db = admin . database ( ) ;
148148
149149 // [START rtdb_order_by_child_nested]
150- const ref = db . ref ( " dinosaurs" ) ;
151- ref . orderByChild ( " dimensions/height" ) . on ( " child_added" , ( snapshot ) => {
152- console . log ( snapshot . key + " was " + snapshot . val ( ) . height + " meters tall" ) ;
150+ const ref = db . ref ( ' dinosaurs' ) ;
151+ ref . orderByChild ( ' dimensions/height' ) . on ( ' child_added' , ( snapshot ) => {
152+ console . log ( snapshot . key + ' was ' + snapshot . val ( ) . height + ' meters tall' ) ;
153153 } ) ;
154154 // [END rtdb_order_by_child_nested]
155155}
@@ -158,8 +158,8 @@ function orderByKey() {
158158 const db = admin . database ( ) ;
159159
160160 // [START rtdb_order_by_key]
161- var ref = db . ref ( " dinosaurs" ) ;
162- ref . orderByKey ( ) . on ( " child_added" , ( snapshot ) => {
161+ var ref = db . ref ( ' dinosaurs' ) ;
162+ ref . orderByKey ( ) . on ( ' child_added' , ( snapshot ) => {
163163 console . log ( snapshot . key ) ;
164164 } ) ;
165165 // [END rtdb_order_by_key]
@@ -169,10 +169,10 @@ function orderByValue() {
169169 const db = admin . database ( ) ;
170170
171171 // [START rtdb_order_by_value]
172- const scoresRef = db . ref ( " scores" ) ;
173- scoresRef . orderByValue ( ) . on ( " value" , ( snapshot ) => {
172+ const scoresRef = db . ref ( ' scores' ) ;
173+ scoresRef . orderByValue ( ) . on ( ' value' , ( snapshot ) => {
174174 snapshot . forEach ( ( data ) => {
175- console . log ( " The " + data . key + " dinosaur's score is " + data . val ( ) ) ;
175+ console . log ( ' The ' + data . key + ' dinosaur\ 's score is ' + data . val ( ) ) ;
176176 } ) ;
177177 } ) ;
178178 // [END rtdb_order_by_value]
@@ -182,8 +182,8 @@ function limitToLast() {
182182 const db = admin . database ( ) ;
183183
184184 // [START rtdb_limit_to_last]
185- const ref = db . ref ( " dinosaurs" ) ;
186- ref . orderByChild ( " weight" ) . limitToLast ( 2 ) . on ( " child_added" , ( snapshot ) => {
185+ const ref = db . ref ( ' dinosaurs' ) ;
186+ ref . orderByChild ( ' weight' ) . limitToLast ( 2 ) . on ( ' child_added' , ( snapshot ) => {
187187 console . log ( snapshot . key ) ;
188188 } ) ;
189189 // [END rtdb_limit_to_last]
@@ -193,8 +193,8 @@ function limitToFirst() {
193193 const db = admin . database ( ) ;
194194
195195 // [START rtdb_limit_to_first]
196- const ref = db . ref ( " dinosaurs" ) ;
197- ref . orderByChild ( " height" ) . limitToFirst ( 2 ) . on ( " child_added" , ( snapshot ) => {
196+ const ref = db . ref ( ' dinosaurs' ) ;
197+ ref . orderByChild ( ' height' ) . limitToFirst ( 2 ) . on ( ' child_added' , ( snapshot ) => {
198198 console . log ( snapshot . key ) ;
199199 } ) ;
200200 // [END rtdb_limit_to_first]
@@ -204,10 +204,10 @@ function limitOrderValue() {
204204 const db = admin . database ( ) ;
205205
206206 // [START rtdb_limit_order_value]
207- const scoresRef = db . ref ( " scores" ) ;
208- scoresRef . orderByValue ( ) . limitToLast ( 3 ) . on ( " value" , ( snapshot ) => {
207+ const scoresRef = db . ref ( ' scores' ) ;
208+ scoresRef . orderByValue ( ) . limitToLast ( 3 ) . on ( ' value' , ( snapshot ) => {
209209 snapshot . forEach ( ( data ) => {
210- console . log ( " The " + data . key + " dinosaur's score is " + data . val ( ) ) ;
210+ console . log ( ' The ' + data . key + ' dinosaur\ 's score is ' + data . val ( ) ) ;
211211 } ) ;
212212 } ) ;
213213 // [END rtdb_limit_order_value]
@@ -217,8 +217,8 @@ function startAt() {
217217 const db = admin . database ( ) ;
218218
219219 // [START rtdb_start_at]
220- const ref = db . ref ( " dinosaurs" ) ;
221- ref . orderByChild ( " height" ) . startAt ( 3 ) . on ( " child_added" , ( snapshot ) => {
220+ const ref = db . ref ( ' dinosaurs' ) ;
221+ ref . orderByChild ( ' height' ) . startAt ( 3 ) . on ( ' child_added' , ( snapshot ) => {
222222 console . log ( snapshot . key ) ;
223223 } ) ;
224224 // [END rtdb_start_at]
@@ -227,8 +227,8 @@ function startAt() {
227227function endAt ( ) {
228228 const db = admin . database ( ) ;
229229 // [START rtdb_end_at]
230- const ref = db . ref ( " dinosaurs" ) ;
231- ref . orderByKey ( ) . endAt ( " pterodactyl" ) . on ( " child_added" , ( snapshot ) => {
230+ const ref = db . ref ( ' dinosaurs' ) ;
231+ ref . orderByKey ( ) . endAt ( ' pterodactyl' ) . on ( ' child_added' , ( snapshot ) => {
232232 console . log ( snapshot . key ) ;
233233 } ) ;
234234 // [END rtdb_end_at]
@@ -238,8 +238,8 @@ function startAtEndAt() {
238238 const db = admin . database ( ) ;
239239
240240 // [START rtdb_start_at_end_at]
241- var ref = db . ref ( " dinosaurs" ) ;
242- ref . orderByKey ( ) . startAt ( "b" ) . endAt ( " b\uf8ff" ) . on ( " child_added" , ( snapshot ) => {
241+ var ref = db . ref ( ' dinosaurs' ) ;
242+ ref . orderByKey ( ) . startAt ( 'b' ) . endAt ( ' b\uf8ff' ) . on ( ' child_added' , ( snapshot ) => {
243243 console . log ( snapshot . key ) ;
244244 } ) ;
245245 // [END rtdb_start_at_end_at]
@@ -249,8 +249,8 @@ function equalTo() {
249249 const db = admin . database ( ) ;
250250
251251 // [START rtdb_equal_to]
252- const ref = db . ref ( " dinosaurs" ) ;
253- ref . orderByChild ( " height" ) . equalTo ( 25 ) . on ( " child_added" , ( snapshot ) => {
252+ const ref = db . ref ( ' dinosaurs' ) ;
253+ ref . orderByChild ( ' height' ) . equalTo ( 25 ) . on ( ' child_added' , ( snapshot ) => {
254254 console . log ( snapshot . key ) ;
255255 } ) ;
256256 // [END rtdb_equal_to]
@@ -260,22 +260,22 @@ function complexCombined() {
260260 const db = admin . database ( ) ;
261261
262262 // [START rtdb_complex_combined]
263- const ref = db . ref ( " dinosaurs" ) ;
264- ref . child ( " stegosaurus" ) . child ( " height" ) . on ( " value" , ( stegosaurusHeightSnapshot ) => {
263+ const ref = db . ref ( ' dinosaurs' ) ;
264+ ref . child ( ' stegosaurus' ) . child ( ' height' ) . on ( ' value' , ( stegosaurusHeightSnapshot ) => {
265265 const favoriteDinoHeight = stegosaurusHeightSnapshot . val ( ) ;
266266
267- const queryRef = ref . orderByChild ( " height" ) . endAt ( favoriteDinoHeight ) . limitToLast ( 2 )
268- queryRef . on ( " value" , ( querySnapshot ) => {
267+ const queryRef = ref . orderByChild ( ' height' ) . endAt ( favoriteDinoHeight ) . limitToLast ( 2 ) ;
268+ queryRef . on ( ' value' , ( querySnapshot ) => {
269269 if ( querySnapshot . numChildren ( ) === 2 ) {
270270 // Data is ordered by increasing height, so we want the first entry
271271 querySnapshot . forEach ( ( dinoSnapshot ) => {
272- console . log ( " The dinosaur just shorter than the stegasaurus is " + dinoSnapshot . key ) ;
272+ console . log ( ' The dinosaur just shorter than the stegasaurus is ' + dinoSnapshot . key ) ;
273273
274274 // Returning true means that we will only loop through the forEach() one time
275275 return true ;
276276 } ) ;
277277 } else {
278- console . log ( " The stegosaurus is the shortest dino" ) ;
278+ console . log ( ' The stegosaurus is the shortest dino' ) ;
279279 }
280280 } ) ;
281281} ) ;
0 commit comments