Skip to content

Commit ca76531

Browse files
committed
update according to new caching behaviour
1 parent af73921 commit ca76531

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

documentation/Prepared-Statements.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ connection.execute('select 1 + ? + ? as result', [5, 6], (err, rows) => {
1313
// close cached statement for 'select 1 + ? + ? as result'. noop if not in cache
1414
connection.unprepare('select 1 + ? + ? as result');
1515
```
16+
Note that `connection.execute()` will cache the prepared statement for better performance, remove the cache with `connection.unprepare()` when you're done.
1617

1718
## Manual prepare / execute
1819

20+
Manually prepared statements doesn't comes with LRU cache and SHOULD be closed using `statement.close()` instead of `connection.unprepare()`.
21+
1922
```js
2023
connection.prepare('select ? + ? as tests', (err, statement) => {
2124
// statement.parameters - array of column definitions, length === number of params, here 2
@@ -27,9 +30,9 @@ connection.prepare('select ? + ? as tests', (err, statement) => {
2730
// -> [ { tests: 3 } ]
2831
});
2932

30-
// do not use statement.close(), use connection.unprepare() to remove lru cache properly.
33+
// don't use connection.unprepare(), it won't work!
3134
// note that there is no callback here. There is no statement close ack at protocol level.
32-
connection.unprepare('select ? + ? as tests');
35+
statement.close();
3336
});
3437
```
3538
Note that you should not use statement after connection reset (`changeUser()` or disconnect). Statement scope is connection, you need to prepare statement for each new connection in order to use it.

promise.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ export function createConnection(
140140
export function createPool(config: PoolOptions): Pool;
141141

142142
export interface PreparedStatementInfo {
143-
/**
144-
* Close the prepared statement. This method DO NOT REMOVE the statement cache, and should only be used internally. Use {@link Connection.unprepare} instead when you've done with prepared statement.
145-
*/
146143
close(): Promise<void>;
147144
execute(parameters: any[]): Promise<[RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader, FieldPacket[]]>;
148145
}

0 commit comments

Comments
 (0)