Skip to content

Commit d9c2b6d

Browse files
committed
chore: polishing documentation
1 parent e6ee95d commit d9c2b6d

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

documentation/en/TypeScript-Examples.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ npm install --save-dev @types/node
88

99
> The `@types/node` ensure the proper interaction between **TypeScript** and the **Node.js** modules used by **MySQL2** (*net*, *events*, *stream*, *tls*, etc.).
1010
11-
## Import
11+
## Usage
1212
You can import **MySQL2** in two ways:
13+
- By setting the `esModuleInterop` option to `true` in `tsconfig.json`
1314
```ts
14-
import * as mysql from 'mysql2';
15-
import * as mysql from 'mysql2/promise';
16-
17-
// By setting the `esModuleInterop` option to `true` in `tsconfig.json`
1815
import mysql from 'mysql2';
1916
import mysql from 'mysql2/promise';
2017
```
2118

22-
## Connection
19+
- By setting the `esModuleInterop` option to `false` in `tsconfig.json`
20+
```ts
21+
import * as mysql from 'mysql2';
22+
import * as mysql from 'mysql2/promise';
23+
```
24+
25+
### Connection
2326
```ts
2427
import mysql, { ConnectionOptions } from 'mysql2';
2528

@@ -31,7 +34,7 @@ const access: ConnectionOptions = {
3134
const conn = mysql.createConnection(access);
3235
```
3336

34-
## Pool Connection
37+
### Pool Connection
3538
```ts
3639
import mysql, { PoolOptions } from 'mysql2';
3740

@@ -43,8 +46,8 @@ const access: PoolOptions = {
4346
const conn = mysql.createPool(access);
4447
```
4548

46-
## Query and Execute
47-
### A simple query
49+
### Query and Execute
50+
#### A simple query
4851
```ts
4952
conn.query('SELECT 1 + 1 AS `test`;', (_err, rows) => {
5053
/**
@@ -70,8 +73,8 @@ In this example, you need to manually check the output types
7073

7174
---
7275

73-
### Type Specification
74-
#### RowDataPacket[]
76+
## Type Specification
77+
### RowDataPacket[]
7578
An array with the returned rows, for example:
7679

7780
```ts
@@ -101,7 +104,7 @@ conn.query<RowDataPacket[]>('SHOW TABLES FROM `test`;', (_err, rows) => {
101104

102105
---
103106

104-
#### RowDataPacket[][]
107+
### RowDataPacket[][]
105108
- When `rowsAsArray` option is `true`
106109
```ts
107110
import mysql, { RowDataPacket } from 'mysql2';
@@ -154,7 +157,7 @@ conn.query<RowDataPacket[]>('SHOW TABLES FROM `test`;', (_err, rows) => {
154157

155158
---
156159

157-
#### ResultSetHeader
160+
### ResultSetHeader
158161
For `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, etc.
159162
```ts
160163
import mysql, { ResultSetHeader } from 'mysql2';
@@ -186,7 +189,7 @@ conn.query<ResultSetHeader>(sql, (_err, result) => {
186189

187190
---
188191

189-
#### ResultSetHeader[]
192+
### ResultSetHeader[]
190193
For multiples `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, etc. when using `multipleStatements` as `true`
191194

192195
```ts
@@ -232,7 +235,7 @@ conn.query<ResultSetHeader[]>(sql, (_err, results) => {
232235

233236
---
234237

235-
#### ProcedureCallPacket
238+
### ProcedureCallPacket
236239
By performing a **Call Procedure** using `INSERT`, `UPDATE`, etc., the return will be a `ProcedureCallPacket<ResultSetHeader>` (even if you perform multiples queries and set `multipleStatements` to `true`).
237240

238241
> For `CREATE PROCEDURE` and `DROP PROCEDURE`, these returns will be the *default* `ResultSetHeader`.

0 commit comments

Comments
 (0)