@@ -20,48 +20,65 @@ You also need to install an IO provider.
20
20
See ` ./test/all ` for detailed usage.
21
21
22
22
23
+ #### Get a file ref
23
24
``` javascript
24
-
25
25
// Note: Example is for Node.js.
26
26
const {smpi } = require (" sqlite-mpi-client-js" );
27
27
const iop = require (" smpi-iop-node-ffi" );
28
28
29
29
const c = smpi .newClient (iop);
30
30
const f = c .newFileRef (" /tmp/db-file.sqlite" );
31
+ ```
32
+
33
+ #### Write transactions
34
+
35
+ - There is only one active write transaction at a time per SQLite file.
36
+ - This applies at an OS level, for all processes.
37
+
38
+ - Write tx requests will queue when there is an active outstanding write tx.
39
+ - Queued write tx requests will resolve in First In First Out (FIFO) manner.
40
+ - When the promise returned from ` f.getWriteTx() ` resolves, the ` wtx ` is active.
31
41
32
42
33
- // Write Transaction.
43
+ ``` javascript
34
44
const wtx = await f .getWriteTx ();
35
45
36
46
// `q` can be a read or write with write txs.
37
47
await wtx .q (" SELECT 1+1" );
48
+
38
49
await wtx .read (" SELECT 1+1" );
50
+
39
51
await wtx .write (" INSERT ..." );
40
52
41
53
await wtx .commit ();
42
54
// await wtx.rollback();
55
+ ```
43
56
57
+ #### Read transactions
44
58
59
+ - Read transactions are concurrent; you can have many read transactions active and reading from the same database file.
45
60
46
- // Read Transaction.
61
+ ``` javascript
47
62
const rtx = await f .getReadTx ();
48
63
49
64
// `q` must be a read.
50
- const rtx = await f .getReadTx ();
51
65
await rtx .q (" SELECT 1+1" );
52
66
53
67
await rtx .read (" SELECT 1+1" );
54
68
55
69
// No writes.
56
70
// await tx.write("INSERT ...");
57
71
58
-
59
72
await rtx .commit ();
60
73
// await rtx.rollback();
74
+ ```
75
+
61
76
62
77
78
+ #### Params
63
79
64
- // Params
80
+
81
+ ``` javascript
65
82
const wtx = await f .getWriteTx ();
66
83
67
84
// Index based.
@@ -71,7 +88,7 @@ await wtx.write("INSERT INTO t1 (b) VALUES (?1), (?2)", [3, 4]);
71
88
// Key based.
72
89
await wtx .write (" INSERT INTO t1 (b) VALUES (:x), (:y)" , {x: 1 , y: 2 });
73
90
await wtx .write (" INSERT INTO t1 (b) VALUES (@x), (@y)" , {x: 1 , y: 2 });
74
- await rtx .commit ();
91
+ await wtx .commit ();
75
92
```
76
93
77
94
### Notes
0 commit comments