Skip to content

Commit 6afbb54

Browse files
committed
Improve code documentation
1 parent 2d2761e commit 6afbb54

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

index.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class MsSql {
2020
this._inTransaction = false;
2121
}
2222

23+
/**
24+
* Creates a connection pool on demand.
25+
*
26+
* @returns Promise< Connection >
27+
*/
2328
async _pool() {
2429

2530
if ( this._isConnected ) {
@@ -50,18 +55,19 @@ class MsSql {
5055
abortTransactionOnError: true,
5156
encrypt: false
5257
}
53-
}
58+
}
5459
);
5560

5661
this.pool = await mssql.connect( config );
5762
this._isConnected = true;
58-
return this.pool;
63+
return this.pool;
5964
}
6065

6166
/**
6267
* Performs a query or data manipulation command.
6368
*
6469
* @param {string} sql
70+
* @returns Promise< Array< object > >
6571
*/
6672
async query(sql) {
6773
let pool = await this._pool();
@@ -73,25 +79,46 @@ class MsSql {
7379
* Executes a data manipulation command.
7480
*
7581
* @param {string} sql
82+
* @returns Promise< Array< object > >
7683
*/
7784
async execute(sql) {
7885
return await this.query(sql);
7986
}
8087

88+
/**
89+
* Closes a database connection.
90+
*
91+
* @returns Promise<>
92+
*/
8193
async close() {
8294
let pool = await this._pool();
8395
await pool.close();
8496
this._isConnected = false;
8597
}
8698

99+
/**
100+
* Checks whether transaction is supported.
101+
*
102+
* @returns boolean
103+
*/
87104
isTransactionSupported() {
88105
return true;
89106
}
90107

108+
/**
109+
* Checks whether it is in a transaction.
110+
*
111+
* @returns boolean
112+
*/
91113
inTransaction() {
92114
return this._inTransaction;
93115
}
94116

117+
/**
118+
* Begins a transaction.
119+
*
120+
* @returns Promise< boolean >
121+
*/
95122
async beginTransaction() {
96123
if ( this.inTransaction() ) {
97124
false;
@@ -102,6 +129,11 @@ class MsSql {
102129
return this.transaction.begin();
103130
}
104131

132+
/**
133+
* Confirms a transaction.
134+
*
135+
* @returns Promise< boolean >
136+
*/
105137
async commit() {
106138
if ( ! this.inTransaction() ) {
107139
return false;
@@ -110,13 +142,19 @@ class MsSql {
110142
return this.transaction.commit();
111143
}
112144

145+
/**
146+
* Undoes a transaction.
147+
*
148+
* @returns Promise< boolean >
149+
*/
113150
async rollback() {
114151
if ( ! this.inTransaction() ) {
115152
return false;
116153
}
117154
this._inTransaction = false;
118155
return this.transaction.rollback();
119156
}
157+
120158
}
121159

122160
module.exports = {

0 commit comments

Comments
 (0)