@@ -4,39 +4,46 @@ import {
4
4
serverTimestamp ,
5
5
increment ,
6
6
arrayRemove ,
7
+ Timestamp ,
7
8
} from 'firelord'
8
9
9
10
export const dummy = async ( ) => {
10
11
try {
11
- await runTransaction ( db , async transaction => {
12
- // ...
13
- } )
14
12
// OR you can skip 'db'
15
- await runTransaction ( async transaction => {
16
- await transaction . get ( example . doc ( 'lmn' ) ) . then ( docSnapshot => {
17
- const data = docSnapshot . data ( )
18
- } )
13
+ await runTransaction (
14
+ db ,
15
+ async transaction => {
16
+ await transaction . get ( example . doc ( 'lmn' ) ) . then ( docSnapshot => {
17
+ const data = docSnapshot . data ( )
18
+ } )
19
19
20
- transaction . create ( example . doc ( 'lmn' ) , {
21
- a : 500 ,
22
- b : { c : true , d : [ { e : 'efg' } ] } ,
23
- f : { g : serverTimestamp ( ) , h : 3838 } ,
24
- } )
20
+ transaction . create ( example . doc ( 'lmn' ) , {
21
+ a : 500 ,
22
+ b : { c : true , d : [ { e : 'efg' } ] } ,
23
+ f : { g : serverTimestamp ( ) , h : 3838 } ,
24
+ } )
25
25
26
- transaction . set ( example . doc ( 'lmn' ) , {
27
- a : 88 ,
28
- b : { c : false , d : [ { e : 'opq' } ] } ,
29
- f : { g : serverTimestamp ( ) , h : 2929 } ,
30
- } )
26
+ transaction . set ( example . doc ( 'lmn' ) , {
27
+ a : 88 ,
28
+ b : { c : false , d : [ { e : 'opq' } ] } ,
29
+ f : { g : serverTimestamp ( ) , h : 2929 } ,
30
+ } )
31
31
32
- transaction . update ( example . doc ( 'lmn' ) , {
33
- a : increment ( 1 ) ,
34
- b : { d : arrayRemove ( { e : 'rst' } ) } , // nested form
35
- 'f.g' : serverTimestamp ( ) , // dot notation form
36
- } )
32
+ transaction . update ( example . doc ( 'lmn' ) , {
33
+ a : increment ( 1 ) ,
34
+ b : { d : arrayRemove ( { e : 'rst' } ) } , // nested form
35
+ 'f.g' : serverTimestamp ( ) , // dot notation form
36
+ } )
37
37
38
- transaction . delete ( example . doc ( 'lmn' ) )
39
- } )
38
+ transaction . delete ( example . doc ( 'lmn' ) )
39
+ } ,
40
+ { readOnly : true , readTime : Timestamp . now ( ) } // optional
41
+ // we can supply 2 set of options:
42
+ // 1. { readOnly?: false, maxAttempts?: number }
43
+ // note that in case 1 both properties are optional and readOnly is false
44
+ // 2. { readOnly: true, readTime?: Timestamp }
45
+ // note that in case only readTime is optional and readOnly is true
46
+ )
40
47
console . log ( 'Transaction successfully committed!' )
41
48
} catch ( e ) {
42
49
console . log ( 'Transaction failed: ' , e )
0 commit comments