serverless: Improve error when prepare() called after close()

This commit is contained in:
Pekka Enberg
2025-08-06 07:50:12 +03:00
parent 79412ea2cc
commit f53adab4a8

View File

@@ -15,6 +15,7 @@ export interface Config extends SessionConfig {}
export class Connection {
private config: Config;
private session: Session;
private isOpen: boolean = true;
constructor(config: Config) {
if (!config.url) {
@@ -40,6 +41,9 @@ export class Connection {
* ```
*/
prepare(sql: string): Statement {
if (!this.isOpen) {
throw new TypeError("The database connection is not open");
}
return new Statement(this.config, sql);
}
@@ -97,6 +101,7 @@ export class Connection {
* This sends a close request to the server to properly clean up the stream.
*/
async close(): Promise<void> {
this.isOpen = false;
await this.session.close();
}
}