Skip to content

Commit 768057a

Browse files
authored
docs(README): add explanation about using the library option with TS
1 parent 3de17e1 commit 768057a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ let results = await query('SELECT * FROM table WHERE name = ?', ['serverless'])
103103
let results = await query({
104104
sql: 'SELECT * FROM table WHERE name = ?',
105105
timeout: 10000,
106-
values: ['serverless'])
106+
values: ['serverless']
107107
})
108108
```
109109

@@ -206,6 +206,26 @@ Set your own mysql library, wrapped with AWS x-ray for instance
206206
library: require('aws-sdk-xray-node')(require('mysql'));
207207
```
208208

209+
### Consideration when using TypeScript
210+
Currently, our type definitions rely on the `mysql` module.
211+
In order to use a custom library, you will need to do something along the following snippet:
212+
213+
```typescript
214+
import * as serverlessMysql from 'serverless-mysql';
215+
import * as mysql2 from 'mysql2';
216+
217+
const slsMysql = serverlessMysql({
218+
library: mysql2 as any
219+
})
220+
221+
// OR
222+
223+
const slsMysql2 = serverlessMysql({
224+
// @ts-ignore
225+
library: mysql2
226+
})
227+
```
228+
209229
## Events
210230
The module fires seven different types of events: `onConnect`, `onConnectError`, `onRetry`, `onClose`, `onError`, `onKill`, and `onKillError`. These are *reporting* events that allow you to add logging or perform additional actions. You could use these events to short-circuit your handler execution, but using `catch` blocks is preferred. For example, `onError` and `onKillError` are not fatal and will be handled by `serverless-mysql`. Therefore, they will **NOT** `throw` an error and trigger a `catch` block.
211231

0 commit comments

Comments
 (0)