You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/guides/Usage/nodejs.md
+65-1Lines changed: 65 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,17 @@ Using Db2 for IBM i with Node.js is easy. First, install the package:
14
14
npm i @ibm/mapepire-js
15
15
```
16
16
17
+
#### Sample Application
18
+
19
+
See our sample Node.js applications in the [mapepire-samples](https://github.com/Mapepire-IBMi/samples/tree/main/typescript) repository.
20
+
17
21
## Basic architecture
18
22
19
23
mapepire-js is a pooling asynchronous client to an instance of the [mapepire-server](https://github.com/Mapepire-IBMi/mapepire-server). The mapepire-server authorizes and mediates connections to an IBM i Db2 server on behalf of the client.
20
24
21
25
This document illustrates the use of the mapepire-js client. Other language clients and the mapepire-server itself are documented elsewhere.
22
26
23
-
### Simple test
27
+
### Making a connection
24
28
25
29
Credentials belong in an object which can be passed to a `Pool` or `SQLJob`.
26
30
@@ -50,6 +54,53 @@ async function listObjects(library: string) {
50
54
listObjects('QGPL');
51
55
```
52
56
57
+
### Parameters
58
+
59
+
Parameters can be passed to queries when they are being executed.
60
+
61
+
```ts
62
+
const query =job.query<any[]>(`select * from table where col = ?`, {parameters: [`value`]});
63
+
```
64
+
65
+
And it is also possible to pass in batches of parameters:
66
+
67
+
```ts
68
+
const query =job.query<any[]>(
69
+
"update SAMPLE.DELETEME set phone = ? where name = ?",
70
+
{
71
+
parameters: [
72
+
["789-678-6543", "SANJULA"],
73
+
["222-456-1234", "TONGKUN"],
74
+
["123-456-7891", "JAMES"],
75
+
],
76
+
}
77
+
);
78
+
```
79
+
80
+
### Paging
81
+
82
+
Paging can be used to block fetch rows in chunks.
83
+
84
+
```ts
85
+
const query =awaitjob.query<any>("select * FROM SAMPLE.SYSCOLUMNS");
For typical production workloads, a connection pool should be used and created when in your apps startup process.
@@ -62,6 +113,19 @@ const pool = new Pool({ creds, maxSize: 5, startingSize: 3 });
62
113
awaitpool.init();
63
114
```
64
115
116
+
#### Execute in a pool
117
+
118
+
`pool.execute` will automatically find a free job and execute the query. If there are no free jobs, it will find the least busy job and wait for it to become free.
119
+
120
+
```ts
121
+
const pool =newPool({ creds, maxSize: 5, startingSize: 3 });
122
+
123
+
awaitpool.init();
124
+
125
+
const result =awaitpool.execute(`values current user`);
126
+
console.log(result);
127
+
```
128
+
65
129
### Securing
66
130
67
131
By default, Mapepire will always try to connect securely. A majority of the time, servers are using their own self-signed certificate that is not signed by a recognized CA (Certificate Authority). There are two options with the Node.js client:
0 commit comments