Skip to content

Commit

Permalink
+ Added releaseSavepoint() method
Browse files Browse the repository at this point in the history
  • Loading branch information
erayhanoglu committed Sep 23, 2021
1 parent ef27c02 commit 9fc61c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,6 @@ export class Connection extends SafeEventEmitter {
return this._intlCon.startTransaction();
}

/**
* Starts transaction and creates a savepoint
* @param name {string} - Name of the savepoint
*/
savepoint(name: string): Promise<void> {
return this._intlCon.savepoint(name);
}

/**
* Commits current transaction
*/
Expand All @@ -200,6 +192,16 @@ export class Connection extends SafeEventEmitter {
return this._intlCon.rollback();
}

/**
* Starts transaction and creates a savepoint
* @param name {string} - Name of the savepoint
*/
async savepoint(name: string): Promise<void> {
if (!this._intlCon.inTransaction)
await this._intlCon.startTransaction();
return this._intlCon.savepoint(name);
}

/**
* Rolls back current transaction to given savepoint
* @param name {string} - Name of the savepoint
Expand All @@ -208,6 +210,14 @@ export class Connection extends SafeEventEmitter {
return this._intlCon.rollbackToSavepoint(name);
}

/**
* Releases savepoint
* @param name {string} - Name of the savepoint
*/
releaseSavepoint(name: string): Promise<void> {
return this._intlCon.releaseSavepoint(name);
}

protected async _close(): Promise<void> {
if (this._pool) {
await this._pool.release(this);
Expand Down
6 changes: 6 additions & 0 deletions src/IntlConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export class IntlConnection extends SafeEventEmitter {
await this.execute('ROLLBACK TO SAVEPOINT ' + name, {autoCommit: false});
}

async releaseSavepoint(name: string): Promise<void> {
if (!(name && name.match(/^[a-zA-Z]\w+$/)))
throw new Error(`Invalid savepoint "${name}`);
await this.execute('RELEASE SAVEPOINT ' + name, {autoCommit: false});
}

ref(): void {
this._refCount++;
debug('[%s] ref %d', this.processID, this._refCount);
Expand Down

0 comments on commit 9fc61c9

Please sign in to comment.