Skip to content

Commit af73921

Browse files
committed
typing & documentation update for prepared statements
1 parent 6fae0c2 commit af73921

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

documentation/Prepared-Statements.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ connection.prepare('select ? + ? as tests', (err, statement) => {
2727
// -> [ { tests: 3 } ]
2828
});
2929

30+
// do not use statement.close(), use connection.unprepare() to remove lru cache properly.
3031
// note that there is no callback here. There is no statement close ack at protocol level.
31-
statement.close();
32+
connection.unprepare('select ? + ? as tests');
3233
});
3334
```
3435
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export interface Connection extends EventEmitter {
6262
values: any | any[] | { [param: string]: any }
6363
): Promise<[T, FieldPacket[]]>;
6464

65-
unprepare(sql: string): void;
65+
prepare(options: string | QueryOptions): Promise<PreparedStatementInfo>;
66+
unprepare(sql: string | QueryOptions): void;
6667

6768
end(options?: any): Promise<void>;
6869

@@ -137,3 +138,11 @@ export function createConnection(
137138
config: ConnectionOptions
138139
): Promise<Connection>;
139140
export function createPool(config: PoolOptions): Pool;
141+
142+
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+
*/
146+
close(): Promise<void>;
147+
execute(parameters: any[]): Promise<[RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader, FieldPacket[]]>;
148+
}

0 commit comments

Comments
 (0)