mythix-orm-postgresql 1.2.3 → 1.3.2

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.
@@ -174,8 +174,28 @@ class PostgreSQLConnection extends SQLConnectionBase {
174
174
  async transaction(callback, _options) {
175
175
  let options = _options || {};
176
176
  let inheritedThis = Object.create(options.connection || this);
177
+ let lockMode = this.getLockMode(options.lock);
177
178
  let savePointName;
178
179
  let client;
180
+ let lockStatement;
181
+
182
+ if (lockMode && lockMode.lock) {
183
+ let Model = this.getModel(lockMode.modelName);
184
+ if (!Model)
185
+ throw new Error(`${this.constructor.name}::transaction: Request to lock table defined by model "${lockMode.modelName}", but model with that name can not be found.`);
186
+
187
+ let escapedTableName = this.escapeID(Model.getTableName());
188
+ let lockModeStr = (lockMode.mode) ? lockMode.mode : 'ACCESS EXCLUSIVE';
189
+
190
+ if (!lockMode.mode) {
191
+ if (lockMode.read === true && lockMode.write === false)
192
+ lockModeStr = 'EXCLUSIVE';
193
+ else if (lockMode.read === false || lockMode.write === false)
194
+ lockModeStr = 'ACCESS SHARE';
195
+ }
196
+
197
+ lockStatement = `LOCK ${(lockMode.dependents === false) ? 'ONLY ' : 'TABLE '} ${escapedTableName} IN ${lockModeStr} MODE${(lockMode.noWait === true) ? ' NOWAIT' : ''}`;
198
+ }
179
199
 
180
200
  if (!inheritedThis.inTransaction) {
181
201
  client = options.connection;
@@ -185,7 +205,11 @@ class PostgreSQLConnection extends SQLConnectionBase {
185
205
  inheritedThis.inTransaction = client;
186
206
 
187
207
  try {
188
- await inheritedThis.query(`BEGIN${(options.mode) ? ` ${options.mode}` : ' DEFERRABLE'}`, options);
208
+ await inheritedThis.query(`BEGIN${(options.beginArguments) ? ` ${options.beginArguments}` : ''}`, options);
209
+ if (lockStatement)
210
+ await inheritedThis.query(lockStatement, options);
211
+
212
+ // TODO: Need to handle "busy" error
189
213
  } catch (error) {
190
214
  if (!options.connection)
191
215
  await client.release();
@@ -145,6 +145,17 @@ class PostgreSQLQueryGenerator extends SQLQueryGeneratorBase {
145
145
 
146
146
  return `TRUNCATE TABLE${(options.onlySpecifiedTable === true) ? ' ONLY' : ''} ${escapedTableName}${(options.continueIdentity === true) ? ' CONTINUE IDENTITY' : ' RESTART IDENTITY'}${(options.cascade === false) ? ' RESTRICT' : ' CASCADE'}`;
147
147
  }
148
+
149
+ generateSelectQueryOperatorFromQueryEngineOperator(queryPart, operator, value, valueIsReference, options) {
150
+ let sqlOperator = super.generateSelectQueryOperatorFromQueryEngineOperator(queryPart, operator, value, valueIsReference, options);
151
+
152
+ if (sqlOperator === 'LIKE' && queryPart.caseSensitive !== true)
153
+ sqlOperator = 'ILIKE';
154
+ else if (sqlOperator === 'NOT LIKE' && queryPart.caseSensitive !== true)
155
+ sqlOperator = 'NOT ILIKE';
156
+
157
+ return sqlOperator;
158
+ }
148
159
  }
149
160
 
150
161
  module.exports = PostgreSQLQueryGenerator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm-postgresql",
3
- "version": "1.2.3",
3
+ "version": "1.3.2",
4
4
  "description": "PostgreSQL driver for Mythix ORM",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",
@@ -33,18 +33,18 @@
33
33
  },
34
34
  "homepage": "https://github.com/th317erd/mythix-orm-postgresql#readme",
35
35
  "peerDependencies": {
36
- "mythix-orm": "^1.3.0",
37
- "mythix-orm-sql-base": "^1.1.2"
36
+ "mythix-orm": "^1.4.6",
37
+ "mythix-orm-sql-base": "^1.3.2"
38
38
  },
39
39
  "dependencies": {
40
40
  "nife": "^1.11.3",
41
- "pg": "^8.7.3",
41
+ "pg": "^8.8.0",
42
42
  "pg-format": "^1.0.4",
43
43
  "uuid": "^8.3.2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
47
- "eslint": "^8.13.0",
47
+ "eslint": "^8.22.0",
48
48
  "jasmine": "^4.3.0",
49
49
  "moment": "^2.29.4",
50
50
  "nyc": "^15.1.0"