anote-server-libs 0.2.7 → 0.2.10
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.
|
@@ -144,7 +144,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
144
144
|
} else {
|
|
145
145
|
const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
|
|
146
146
|
request.input('1', id);
|
|
147
|
-
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
|
|
147
|
+
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -164,7 +164,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
164
164
|
.then(q => q.rows.map(r => this.buildObject(r)));
|
|
165
165
|
} else {
|
|
166
166
|
const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
|
|
167
|
-
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + ' WHERE id IN ('
|
|
167
|
+
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id IN ('
|
|
168
168
|
+ (ids.length > 0 ? (typeof ids[0] === 'string' ? '\'' + ids.join('\',\'') + '\'' : ids.join(',')) : '') + ')')
|
|
169
169
|
.then(q => q.recordsets[0].map(r => this.buildObject(r)));
|
|
170
170
|
}
|
|
@@ -178,7 +178,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
178
178
|
} else {
|
|
179
179
|
const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
|
|
180
180
|
if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
|
|
181
|
-
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
|
|
181
|
+
return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
|
|
182
182
|
+ (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : ''))
|
|
183
183
|
.then(q => q.recordsets[0].map(r => this.buildObject(r)));
|
|
184
184
|
}
|
|
@@ -196,7 +196,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
196
196
|
const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
|
|
197
197
|
if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
|
|
198
198
|
return Promise.allConcurrent(1)([
|
|
199
|
-
() => request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
|
|
199
|
+
() => request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
|
|
200
200
|
+ (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
|
|
201
201
|
() => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
|
|
202
202
|
]).then(([q1, q2]: [any, any]) => ({
|
|
@@ -219,7 +219,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
219
219
|
if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
|
|
220
220
|
return Promise.allConcurrent(1)([
|
|
221
221
|
() => request.query('SELECT ' + rows.map(r => '"' + r + '"').join(',') + ' FROM ' + this.table
|
|
222
|
-
+ ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
222
|
+
+ ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
223
223
|
+ (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
|
|
224
224
|
() => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
|
|
225
225
|
]).then(([q1, q2]: [any, any]) => ({
|
package/package.json
CHANGED
|
@@ -116,13 +116,9 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
|
|
|
116
116
|
} else {
|
|
117
117
|
finish();
|
|
118
118
|
}
|
|
119
|
-
}).catch((err: any) => {
|
|
120
|
-
if(repo.db) dbClient.release();
|
|
121
|
-
else dbClient.rollback();
|
|
122
|
-
throw err;
|
|
123
119
|
});
|
|
124
120
|
}).catch(err => {
|
|
125
|
-
// Error connecting to database, restarting worker after the timeout as well...
|
|
121
|
+
// Error connecting to database or acquiring transaction, restarting worker after the timeout as well...
|
|
126
122
|
res.status(500).json({
|
|
127
123
|
error: {
|
|
128
124
|
errorKey: 'internal.db',
|