db-crud-api 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/mssql.js CHANGED
@@ -1,278 +1,274 @@
1
- 'use strict';
2
-
3
- import sql from 'mssql';
4
-
5
- const pools = {};
6
-
7
- // Common
8
- function stringifyValue(fieldName, value, tSchema) {
9
- if (value == undefined) { return 'null' }
10
- if (typeof value !== 'string' || value.trimStart().charAt(0) !== '[') {
11
- if (tSchema.table.fields && tSchema.table.fields[fieldName] && tSchema.table.fields[fieldName].type) {
12
- if (tSchema.table.fields[fieldName].type == 'datetime') {
13
- if (typeof value == 'datetime' || typeof value == 'object') return `\'${value.toISOString()}\'`;
14
- if (typeof value == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
15
- return value;
16
- }
17
- if (tSchema.table.fields[fieldName].type == 'boolean' && typeof value == 'boolean') return `\'${value}\'`;
18
- if (tSchema.table.fields[fieldName].type == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
19
- if (tSchema.table.fields[fieldName].type == 'uuid' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
20
- }
21
- else {
22
- // if (typeof value == 'datetime') return `\'${value.toISOString()}\'`;
23
- if (typeof value == 'boolean') return `\'${value}\'`;
24
- if (typeof value == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
25
- }
26
- }
27
- return value;
28
- }
29
-
30
- // Create config object for pool
31
- export function prepareConnection(tSchema) {
32
- return {
33
- id: `${tSchema.server.realName}-${tSchema.database.realName}-${tSchema.server.user}`,
34
- server: ((tSchema.server.instance && tSchema.server.instance != 'DEFAULT') ? (tSchema.server.realName + '\\' + tSchema.server.instance) : tSchema.server.realName) ?? 'localhost',
35
- port: tSchema.server.port,
36
- user: tSchema.server.user,
37
- password: tSchema.server.password,
38
- options: {
39
- appName: tSchema.server.options?.appName,
40
- encrypt: tSchema.server.options?.encrypt ?? false, // true for azure
41
- trustServerCertificate: tSchema.server.options?.trustServerCertificate ?? true // true for local dev / self-signed certs
42
- },
43
- database: tSchema.database.realName
44
- };
45
- };
46
-
47
- // Close connection
48
- export async function closeConnection(connection) {
49
- let pool = pools[connection.id];
50
- if (pool) {
51
- await pool.close(); // wait pool is closed
52
- pools[connection.id] = undefined; // remove pool from pools
53
- }
54
- }
55
-
56
- // Close all connections
57
- export async function closeAllConnections() {
58
- for (let poolId in pools) {
59
- if (!pools.hasOwnProperty(poolId)) continue;
60
- let pool = pools[poolId];
61
- if (pool) {
62
- await pool.close(); // wait pool is closed
63
- pool = undefined; // remove pool from pools
64
- }
65
- }
66
- }
67
-
68
- // Query
69
- export async function query(connection, dbOpes) {
70
-
71
- // Prepare pool
72
- let pool = pools[connection.id]; // Try to get an existing pool
73
- if (!pool) {
74
- pool = new sql.ConnectionPool(connection); // Create new pool
75
- try { await pool.connect(); // wait that connection are made
76
- } catch(err) { throw(err); } // using original error
77
- pools[connection.id] = pool; // add new pool to pools
78
- }
79
-
80
- // Prepare sql statement
81
- let sqlString = '';
82
- let sqlRequest = pool.request();
83
- // if exists, input params will be added to request
84
- if (Array.isArray(dbOpes)) dbOpes.forEach((dbOpe, index) => { sqlString += ToSql(dbOpe, sqlRequest); });
85
- else sqlString += ToSql(dbOpes, sqlRequest);
86
-
87
- // Run query
88
- const sqlresult = await sqlRequest.query(sqlString);
89
-
90
- // Return result
91
- return sqlresult;
92
- }
93
-
94
- // Normalize field name
95
- //function toFieldName(s) {
96
- // if ( s.trimStart().charAt(0) === '[' ) return s;
97
- // else return `\[${s}\]`;
98
- //}
99
-
100
- // Compose fully qualified table name
101
- function fullyQualifiedTableName(tSchema) {
102
- return (tSchema.database.realName + '.' + (tSchema.table.schema ?? '') + '.' + tSchema.table.realName);
103
- }
104
-
105
- // Parse oprations object to sql string
106
- function ToSql(dbOpe, sqlRequest) {
107
- if (dbOpe.get) return getToSql(dbOpe, sqlRequest);
108
- if (dbOpe.patch) return patchToSql(dbOpe, sqlRequest);
109
- if (dbOpe.put) return putToSql(dbOpe, sqlRequest);
110
- if (dbOpe.delete) return deleteToSql(dbOpe, sqlRequest);
111
- if (dbOpe.execute) return executeToSql(dbOpe, sqlRequest);
112
- if (dbOpe.begin) return beginToSql(dbOpe, sqlRequest);
113
- if (dbOpe.commit) return commitToSql(dbOpe, sqlRequest);
114
- if (dbOpe.passthrough) return passthroughToSql(dbOpe, sqlRequest);
115
- }
116
-
117
- // Parse operation object to sql string without any trasformation.
118
- function passthroughToSql(dbOpe, sqlRequest) {
119
-
120
- let result = "";
121
-
122
- if (dbOpe.passthrough.command) {
123
- result += dbOpe.passthrough.command;
124
- }
125
- else { throw new Error('command is missing.'); }
126
-
127
- if (dbOpe.passthrough.params) addParams(dbOpe.passthrough.params, sqlRequest);
128
-
129
- return result;
130
- }
131
-
132
- // Parse get operation object to sql string
133
- function getToSql(dbOpe, sqlRequest) {
134
- let _first = true;
135
-
136
- let result = 'select '
137
-
138
- if ((dbOpe.get.options) && (Object.keys(dbOpe.get.options).length > 0)) {
139
- if (Array.isArray(dbOpe.get.options)) result += dbOpe.get.options.join(' ') + ' ';
140
- else result += dbOpe.get.options + ' ';
141
- }
142
-
143
- if ((dbOpe.get.fields) && (Object.keys(dbOpe.get.fields).length > 0)) {
144
- if (Array.isArray(dbOpe.get.fields)) result += dbOpe.get.fields.join(', ');
145
- else result += dbOpe.get.fields;
146
- }
147
- else { throw new Error('fields is missing.'); }
148
-
149
- result += ' from ' + fullyQualifiedTableName(dbOpe.get.schema);
150
-
151
- if ((dbOpe.get.filters) && (Object.keys(dbOpe.get.filters).length > 0)) {
152
- if (Array.isArray(dbOpe.get.filters)) result += ' where ' + dbOpe.get.filters.join(' ');
153
- else result += ' where ' + dbOpe.get.filters;
154
- }
155
-
156
- if ((dbOpe.get.groups) && (Object.keys(dbOpe.get.groups).length > 0)) {
157
- if (Array.isArray(dbOpe.get.groups)) result += ' group by ' + dbOpe.get.groups.join(', ');
158
- else result += ' group by ' + dbOpe.get.groups;
159
- }
160
-
161
- if ((dbOpe.get.groupsFilters) && (Object.keys(dbOpe.get.groupsFilters).length > 0)) {
162
- if (Array.isArray(dbOpe.get.groupsFilters)) result += ' having ' + dbOpe.get.groupsFilters.join(' ');
163
- else result += ' having ' + dbOpe.get.groupsFilters;
164
- }
165
-
166
- if ((dbOpe.get.orderBy) && (Object.keys(dbOpe.get.orderBy).length > 0)) {
167
- if (Array.isArray(dbOpe.get.orderBy)) result += ' order by ' + dbOpe.get.orderBy.join(', ');
168
- else result += ' order by ' + dbOpe.get.orderBy;
169
- }
170
-
171
- if (dbOpe.get.params) addParams(dbOpe.get.params, sqlRequest);
172
-
173
- result += ';'
174
-
175
- return result;
176
- }
177
-
178
- // Parse patch operation object to sql string
179
- function patchToSql(dbOpe, sqlRequest) {
180
- let result = 'update ' + fullyQualifiedTableName(dbOpe.patch.schema);
181
-
182
- if (dbOpe.patch.sets) { result += ' set ' + Object.entries(dbOpe.patch.sets).map(e => { return e[0] + '=' + stringifyValue(e[0], e[1], dbOpe.patch.schema) }).join(', '); }
183
- else { throw new Error('sets is missing.'); }
184
-
185
- if ((dbOpe.patch.filters) && (Object.keys(dbOpe.patch.filters).length > 0)) {
186
- if (Array.isArray(dbOpe.patch.filters)) result += ' where ' + dbOpe.patch.filters.join(' ');
187
- else result += ' where ' + dbOpe.patch.filters;
188
- }
189
-
190
- if (dbOpe.patch.params) addParams(dbOpe.patch.params, sqlRequest);
191
-
192
- result += ';'
193
-
194
- return result;
195
- }
196
-
197
- // Parse put (add) operation object to sql string
198
- function putToSql(dbOpe, sqlRequest) {
199
- let result = 'insert into ' + fullyQualifiedTableName(dbOpe.put.schema);
200
-
201
- if ((dbOpe.put.sets) && (Object.keys(dbOpe.put.sets).length > 0)) {
202
- let result_f = ' ('; let result_v = ' values (';
203
- let _first = true;
204
- for (const [key, value] of Object.entries(dbOpe.put.sets)) {
205
- if (!_first) { result_f += ', '; result_v += ', '; } else { _first = false }
206
- if (key || value) { result_f += key; result_v += stringifyValue(key, value, dbOpe.put.schema); }
207
- }
208
- result_f += ')'; result_v += ')';
209
- result += result_f + result_v;
210
- }
211
- else { throw new Error('sets is missing.'); }
212
-
213
- if (dbOpe.put.params) addParams(dbOpe.put.params, sqlRequest);
214
-
215
- result += ';'
216
-
217
- return result;
218
- }
219
-
220
- // Parse delete operation object to sql string
221
- function deleteToSql(dbOpe, sqlRequest) {
222
- let result = 'delete from ' + fullyQualifiedTableName(dbOpe.delete.schema);
223
-
224
- if ((dbOpe.delete.filters) && (Object.keys(dbOpe.delete.filters).length > 0)) {
225
- if (Array.isArray(dbOpe.delete.filters)) result += ' where ' + dbOpe.delete.filters.join(' ');
226
- else result += ' where ' + dbOpe.delete.filters;
227
- }
228
-
229
- if (dbOpe.delete.params) addParams(dbOpe.delete.params, sqlRequest);
230
-
231
- result += ';'
232
-
233
- return result;
234
- }
235
-
236
- // Parse execute operation object to sql string
237
- function executeToSql(dbOpe, sqlRequest) {
238
- let result = "execute ";
239
-
240
- if (dbOpe.execute.schema.procedure) {
241
- result += dbOpe.execute.schema.procedure.command;
242
- }
243
- else { throw new Error('command is missing.'); }
244
-
245
- if (dbOpe.execute.params) addParams(dbOpe.execute.params, sqlRequest);
246
-
247
- result += ';'
248
-
249
- return result;
250
- }
251
-
252
- // Parse begin operation object to sql string
253
- function beginToSql(dbOpe, sqlRequest) {
254
- return "BEGIN TRY BEGIN TRANSACTION;";
255
- }
256
-
257
- // Parse commit operation object to sql string
258
- function commitToSql(dbOpe, sqlRequest) {
259
- return "IF @@TRANCOUNT > 0 COMMIT TRANSACTION; \
260
- END TRY \
261
- BEGIN CATCH \
262
- IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; \
263
- DECLARE @ErrorMessage NVARCHAR(4000); \
264
- DECLARE @ErrorSeverity INT; \
265
- DECLARE @ErrorState INT; \
266
- RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState); \
267
- END CATCH";
268
- }
269
-
270
- // Add input parameters to pool.request
271
- function addParams(params, sqlRequest) {
272
- if (params) {
273
- for (const [key, value] of Object.entries(params)) {
274
- sqlRequest.input(key, value)
275
- }
276
- }
277
- return;
1
+ 'use strict';
2
+
3
+ import sql from 'mssql';
4
+
5
+ const pools = {};
6
+
7
+ // Common
8
+ function stringifyValue(fieldName, value, tSchema) {
9
+ if (value == undefined) { return 'null' }
10
+ if (typeof value !== 'string' || value.trimStart().charAt(0) !== '[') {
11
+ if (tSchema.table.fields && tSchema.table.fields[fieldName] && tSchema.table.fields[fieldName].type) {
12
+ if (tSchema.table.fields[fieldName].type == 'datetime') {
13
+ if (typeof value == 'datetime' || typeof value == 'object') return `\'${value.toISOString()}\'`;
14
+ if (typeof value == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
15
+ return value;
16
+ }
17
+ if (tSchema.table.fields[fieldName].type == 'boolean' && typeof value == 'boolean') return `\'${value}\'`;
18
+ if (tSchema.table.fields[fieldName].type == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
19
+ if (tSchema.table.fields[fieldName].type == 'uuid' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
20
+ }
21
+ else {
22
+ // if (typeof value == 'datetime') return `\'${value.toISOString()}\'`;
23
+ if (typeof value == 'boolean') return `\'${value}\'`;
24
+ if (typeof value == 'string' && value.trimStart().charAt(0) !== '\'' && value.trimStart().charAt(0) !== '\"') return `\'${value}\'`;
25
+ }
26
+ }
27
+ return value;
28
+ }
29
+
30
+ // Create config object for pool
31
+ export function prepareConnection(tSchema) {
32
+ return {
33
+ id: `${tSchema.server.realName}-${tSchema.database.realName}-${tSchema.server.user}`,
34
+ server: ((tSchema.server.instance && tSchema.server.instance != 'DEFAULT') ? (tSchema.server.realName + '\\' + tSchema.server.instance) : tSchema.server.realName) ?? 'localhost',
35
+ port: tSchema.server.port,
36
+ user: tSchema.server.user,
37
+ password: tSchema.server.password,
38
+ options: {
39
+ appName: tSchema.server.options?.appName,
40
+ encrypt: tSchema.server.options?.encrypt ?? false, // true for azure
41
+ trustServerCertificate: tSchema.server.options?.trustServerCertificate ?? true // true for local dev / self-signed certs
42
+ },
43
+ pool: tSchema.server.pool,
44
+ database: tSchema.database.realName
45
+ };
46
+ };
47
+
48
+ // Close connection
49
+ export async function closeConnection(connection) {
50
+ let pool = pools[connection.id];
51
+ if (pool) {
52
+ await pool.close(); // wait pool is closed
53
+ pools[connection.id] = undefined; // remove pool from pools
54
+ }
55
+ }
56
+
57
+ // Close all connections
58
+ export async function closeAllConnections() {
59
+ for (let poolId in pools) {
60
+ if (!pools.hasOwnProperty(poolId)) continue;
61
+ let pool = pools[poolId];
62
+ if (pool) {
63
+ await pool.close(); // wait pool is closed
64
+ pool = undefined; // remove pool from pools
65
+ }
66
+ }
67
+ }
68
+
69
+ // Query
70
+ export async function query(connection, dbOpes) {
71
+
72
+ // Prepare pool
73
+ let pool = pools[connection.id]; // Try to get an existing pool
74
+ if (!pool) {
75
+ pool = new sql.ConnectionPool(connection); // Create new pool
76
+ try { await pool.connect(); // wait that connection are made
77
+ } catch(err) { throw(err); } // using original error
78
+ pools[connection.id] = pool; // add new pool to pools
79
+ }
80
+
81
+ // Prepare sql statement
82
+ let sqlString = '';
83
+ let sqlRequest = pool.request();
84
+ // if exists, input params will be added to request
85
+ if (Array.isArray(dbOpes)) dbOpes.forEach((dbOpe, index) => { sqlString += ToSql(dbOpe, sqlRequest); });
86
+ else sqlString += ToSql(dbOpes, sqlRequest);
87
+
88
+ // Run query
89
+ const sqlresult = await sqlRequest.query(sqlString);
90
+
91
+ // Return a single object if there is only 1 row
92
+ if (sqlresult.recordsets.length === 0) return;
93
+ if (sqlresult.recordsets.length === 1) return sqlresult.recordsets[0];
94
+ else return sqlresult.recordsets;
95
+ }
96
+
97
+ // Normalize field name
98
+ //function toFieldName(s) {
99
+ // if ( s.trimStart().charAt(0) === '[' ) return s;
100
+ // else return `\[${s}\]`;
101
+ //}
102
+
103
+ // Compose fully qualified table name
104
+ function fullyQualifiedTableName(tSchema) {
105
+ return (tSchema.database.realName + '.' + (tSchema.table.schema ?? '') + '.' + tSchema.table.realName);
106
+ }
107
+
108
+ // Parse oprations object to sql string
109
+ function ToSql(dbOpe, sqlRequest) {
110
+ if (dbOpe.get) return getToSql(dbOpe, sqlRequest);
111
+ if (dbOpe.patch) return patchToSql(dbOpe, sqlRequest);
112
+ if (dbOpe.put) return putToSql(dbOpe, sqlRequest);
113
+ if (dbOpe.delete) return deleteToSql(dbOpe, sqlRequest);
114
+ if (dbOpe.execute) return executeToSql(dbOpe, sqlRequest);
115
+ if (dbOpe.begin) return beginToSql(dbOpe, sqlRequest);
116
+ if (dbOpe.commit) return commitToSql(dbOpe, sqlRequest);
117
+ if (dbOpe.passthrough) return passthroughToSql(dbOpe, sqlRequest);
118
+ }
119
+
120
+ // Parse operation object to sql string without any trasformation.
121
+ function passthroughToSql(dbOpe, sqlRequest) {
122
+
123
+ let result = "";
124
+
125
+ if (dbOpe.passthrough.command) {
126
+ result += dbOpe.passthrough.command;
127
+ }
128
+ else { throw new Error('command is missing.'); }
129
+
130
+ if (dbOpe.passthrough.params) addParams(dbOpe.passthrough.params, sqlRequest);
131
+
132
+ return result;
133
+ }
134
+
135
+ // Parse get operation object to sql string
136
+ function getToSql(dbOpe, sqlRequest) {
137
+ let _first = true;
138
+
139
+ let result = 'select '
140
+
141
+ if ((dbOpe.get.options) && (Object.keys(dbOpe.get.options).length > 0)) {
142
+ if (Array.isArray(dbOpe.get.options)) result += dbOpe.get.options.join(' ') + ' ';
143
+ else result += dbOpe.get.options + ' ';
144
+ }
145
+
146
+ if ((dbOpe.get.fields) && (Object.keys(dbOpe.get.fields).length > 0)) {
147
+ if (Array.isArray(dbOpe.get.fields)) result += dbOpe.get.fields.join(', ');
148
+ else result += dbOpe.get.fields;
149
+ }
150
+ else { throw new Error('fields is missing.'); }
151
+
152
+ result += ' from ' + fullyQualifiedTableName(dbOpe.get.schema);
153
+
154
+ if ((dbOpe.get.filters) && (Object.keys(dbOpe.get.filters).length > 0)) {
155
+ if (Array.isArray(dbOpe.get.filters)) result += ' where ' + dbOpe.get.filters.join(' ');
156
+ else result += ' where ' + dbOpe.get.filters;
157
+ }
158
+
159
+ if ((dbOpe.get.groups) && (Object.keys(dbOpe.get.groups).length > 0)) {
160
+ if (Array.isArray(dbOpe.get.groups)) result += ' group by ' + dbOpe.get.groups.join(', ');
161
+ else result += ' group by ' + dbOpe.get.groups;
162
+ }
163
+
164
+ if ((dbOpe.get.groupsFilters) && (Object.keys(dbOpe.get.groupsFilters).length > 0)) {
165
+ if (Array.isArray(dbOpe.get.groupsFilters)) result += ' having ' + dbOpe.get.groupsFilters.join(' ');
166
+ else result += ' having ' + dbOpe.get.groupsFilters;
167
+ }
168
+
169
+ if ((dbOpe.get.orderBy) && (Object.keys(dbOpe.get.orderBy).length > 0)) {
170
+ if (Array.isArray(dbOpe.get.orderBy)) result += ' order by ' + dbOpe.get.orderBy.join(', ');
171
+ else result += ' order by ' + dbOpe.get.orderBy;
172
+ }
173
+
174
+ if (dbOpe.get.params) addParams(dbOpe.get.params, sqlRequest);
175
+
176
+ result += ';'
177
+
178
+ return result;
179
+ }
180
+
181
+ // Parse patch operation object to sql string
182
+ function patchToSql(dbOpe, sqlRequest) {
183
+ let result = 'update ' + fullyQualifiedTableName(dbOpe.patch.schema);
184
+
185
+ if (dbOpe.patch.sets) { result += ' set ' + Object.entries(dbOpe.patch.sets).map(e => { return e[0] + '=' + stringifyValue(e[0], e[1], dbOpe.patch.schema) }).join(', '); }
186
+ else { throw new Error('sets is missing.'); }
187
+
188
+ if ((dbOpe.patch.filters) && (Object.keys(dbOpe.patch.filters).length > 0)) {
189
+ if (Array.isArray(dbOpe.patch.filters)) result += ' where ' + dbOpe.patch.filters.join(' ');
190
+ else result += ' where ' + dbOpe.patch.filters;
191
+ }
192
+
193
+ if (dbOpe.patch.params) addParams(dbOpe.patch.params, sqlRequest);
194
+
195
+ result += ';'
196
+
197
+ return result;
198
+ }
199
+
200
+ // Parse put (add) operation object to sql string
201
+ function putToSql(dbOpe, sqlRequest) {
202
+ let result = 'insert into ' + fullyQualifiedTableName(dbOpe.put.schema);
203
+
204
+ if ((dbOpe.put.sets) && (Object.keys(dbOpe.put.sets).length > 0)) {
205
+ let result_f = ' ('; let result_v = ' values (';
206
+ let _first = true;
207
+ for (const [key, value] of Object.entries(dbOpe.put.sets)) {
208
+ if (!_first) { result_f += ', '; result_v += ', '; } else { _first = false }
209
+ if (key || value) { result_f += key; result_v += stringifyValue(key, value, dbOpe.put.schema); }
210
+ }
211
+ result_f += ')'; result_v += ')';
212
+ result += result_f + result_v;
213
+ }
214
+ else { throw new Error('sets is missing.'); }
215
+
216
+ if (dbOpe.put.params) addParams(dbOpe.put.params, sqlRequest);
217
+
218
+ result += ';'
219
+
220
+ return result;
221
+ }
222
+
223
+ // Parse delete operation object to sql string
224
+ function deleteToSql(dbOpe, sqlRequest) {
225
+ let result = 'delete from ' + fullyQualifiedTableName(dbOpe.delete.schema);
226
+
227
+ if ((dbOpe.delete.filters) && (Object.keys(dbOpe.delete.filters).length > 0)) {
228
+ if (Array.isArray(dbOpe.delete.filters)) result += ' where ' + dbOpe.delete.filters.join(' ');
229
+ else result += ' where ' + dbOpe.delete.filters;
230
+ }
231
+
232
+ if (dbOpe.delete.params) addParams(dbOpe.delete.params, sqlRequest);
233
+
234
+ result += ';'
235
+
236
+ return result;
237
+ }
238
+
239
+ // Parse execute operation object to sql string
240
+ function executeToSql(dbOpe, sqlRequest) {
241
+ let result = "execute ";
242
+
243
+ if (dbOpe.execute.schema.procedure) {
244
+ result += dbOpe.execute.schema.procedure.command;
245
+ if (dbOpe.execute.arguments) result += (' ' + dbOpe.execute.arguments);
246
+ }
247
+ else { throw new Error('missing procedure/function name.'); }
248
+
249
+ if (dbOpe.execute.params) addParams(dbOpe.execute.params, sqlRequest);
250
+
251
+ result += ';'
252
+
253
+ return result;
254
+ }
255
+
256
+ // Parse begin operation object to sql string
257
+ function beginToSql(dbOpe, sqlRequest) {
258
+ return "BEGIN TRANSACTION;";
259
+ }
260
+
261
+ // Parse commit operation object to sql string
262
+ function commitToSql(dbOpe, sqlRequest) {
263
+ return "IF @@TRANCOUNT > 0 COMMIT TRANSACTION;";
264
+ }
265
+
266
+ // Add input parameters to pool.request
267
+ function addParams(params, sqlRequest) {
268
+ if (params) {
269
+ for (const [key, value] of Object.entries(params)) {
270
+ sqlRequest.input(key, value)
271
+ }
272
+ }
273
+ return;
278
274
  }