Skip to content

Commit 712fd8e

Browse files
committed
Major commit
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
1 parent 14261cd commit 712fd8e

File tree

5 files changed

+737
-133
lines changed

5 files changed

+737
-133
lines changed

src/content/docs/guides/Clients.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Available:
1313
* [Java](/guides/usage/java)
1414

1515
Future SDKs:
16+
1617
* C#/.NET Core
1718
* PHP
1819
* Go
1920

20-
2121
### App examples
2222

2323
The [samples repository](https://github.com/Mapepire-IBMi/samples) contains a number of sample client applications using Mapepire!

src/content/docs/guides/Usage/nodejs.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ Using Db2 for IBM i with Node.js is easy. First, install the package:
1414
npm i @ibm/mapepire-js
1515
```
1616

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+
1721
## Basic architecture
1822

1923
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.
2024

2125
This document illustrates the use of the mapepire-js client. Other language clients and the mapepire-server itself are documented elsewhere.
2226

23-
### Simple test
27+
### Making a connection
2428

2529
Credentials belong in an object which can be passed to a `Pool` or `SQLJob`.
2630

@@ -50,6 +54,53 @@ async function listObjects(library: string) {
5054
listObjects('QGPL');
5155
```
5256

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 = await job.query<any>("select * FROM SAMPLE.SYSCOLUMNS");
86+
let res = await query.execute();
87+
while (!res.is_done) {
88+
res = await query.fetchMore(300);
89+
console.table(res.data);
90+
}
91+
await query.close();
92+
await job.close();
93+
```
94+
95+
### CL commands
96+
97+
CL commands can be executed through an SQLJob.
98+
99+
```ts
100+
const query = await job.clcommand("INVALIDCOMMAND");
101+
const res = await query.execute();
102+
```
103+
53104
### Pooling
54105

55106
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 });
62113
await pool.init();
63114
```
64115

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 = new Pool({ creds, maxSize: 5, startingSize: 3 });
122+
123+
await pool.init();
124+
125+
const result = await pool.execute(`values current user`);
126+
console.log(result);
127+
```
128+
65129
### Securing
66130

67131
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

Comments
 (0)