mythix-orm-sql-base 1.11.1 → 1.12.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.
@@ -6,6 +6,9 @@ export declare interface ModelDataFromQueryResults {
6
6
  }
7
7
 
8
8
  declare class SQLConnectionBase extends ConnectionBase {
9
+ public isLimitSupportedInContext(options?: GenericObject): boolean;
10
+ public isOrderSupportedInContext(options?: GenericObject): boolean | string;
11
+
9
12
  public prepareArrayValuesForSQL(array: Array<any>): Array<any>;
10
13
  public generateSavePointName(): string;
11
14
 
@@ -82,6 +82,46 @@ class SQLConnectionBase extends ConnectionBase {
82
82
  return parts.map((part) => SqlString.escapeId(part).replace(/^`/, '"').replace(/`$/, '"')).join('.');
83
83
  }
84
84
 
85
+ /// This method is called (and often provided)
86
+ /// by the underlying database driver to see
87
+ /// if a `LIMIT` clause is allowed to appear in
88
+ /// a given context/operation.
89
+ ///
90
+ /// Arguments:
91
+ /// options: object
92
+ /// Driver specific options for the context.
93
+ ///
94
+ /// Return: boolean
95
+ isLimitSupportedInContext(options) {
96
+ return true;
97
+ }
98
+
99
+ /// This method is called (and often provided)
100
+ /// by the underlying database driver to see
101
+ /// if an `ORDER BY` clause is allowed to appear in
102
+ /// a given context/operation.
103
+ ///
104
+ /// Arguments:
105
+ /// options: object
106
+ /// Driver specific options for the context.
107
+ ///
108
+ /// Return: boolean
109
+ isOrderSupportedInContext(_options) {
110
+ let options = _options || {};
111
+ if (options.isSubQuery) {
112
+ let subQueryOperator = options.subQueryOperator;
113
+ if (subQueryOperator === 'EXISTS' || subQueryOperator === 'NOT EXISTS')
114
+ return false;
115
+
116
+ if (subQueryOperator === 'ANY' || subQueryOperator === 'ALL')
117
+ return true;
118
+
119
+ return 'PROJECTION_ONLY';
120
+ }
121
+
122
+ return true;
123
+ }
124
+
85
125
  /// Prepare an array of values for use in an `IN` statement.
86
126
  /// This method will flatten the provided array, and then
87
127
  /// will filter out all non-primitive values from the array.
@@ -680,7 +720,7 @@ class SQLConnectionBase extends ConnectionBase {
680
720
  if (!queryEngine)
681
721
  throw new Error(`${this.constructor.name}::updateAll: Model class or query is required to update.`);
682
722
 
683
- let options = Object.assign({}, _options || {}, { isUpdateOperation: true });
723
+ let options = Object.assign({}, _options || {}, { isUpdateOperation: true, noPrimaryKey: true });
684
724
  queryEngine = await this.finalizeQuery('update', queryEngine, options);
685
725
 
686
726
  let rootModel = queryEngine.getOperationContext().rootModel;
@@ -2077,23 +2077,10 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
2077
2077
  /// Return: Array<string>
2078
2078
  /// Return an array of `CREATE INDEX` statements. If the `index` property on the provided
2079
2079
  /// `field` is falsy or empty, then an empty array will be returned instead.
2080
- generateColumnIndexes(Model, field, _options) {
2081
- let indexes = Nife.toArray(field.index).filter((index) => {
2082
- if (index === true)
2083
- return true;
2084
-
2085
- return (Nife.instanceOf(index, 'string', 'array') && Nife.isNotEmpty(index));
2086
- });
2087
-
2088
- if (indexes.length === 0)
2089
- return [];
2090
-
2091
- let options = _options || {};
2092
- return indexes.map((indexNames) => {
2093
- let fieldIndexNames = [ field.fieldName ];
2094
- if (indexNames !== true)
2095
- fieldIndexNames = fieldIndexNames.concat(indexNames);
2080
+ generateColumnIndexes(Model, field, options) {
2081
+ let indexes = this.getIndexFieldsFromFieldIndex(field);
2096
2082
 
2083
+ return indexes.map((fieldIndexNames) => {
2097
2084
  return this.generateCreateIndexStatement(Model, fieldIndexNames, options);
2098
2085
  });
2099
2086
  }
@@ -2710,7 +2697,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
2710
2697
  if (!ModelBase.isModel(model)) {
2711
2698
  let newModel = new Model();
2712
2699
  newModel.clearDirty();
2713
- newModel.setAttributes(model);
2700
+ newModel.setAttributes(model, options.noPrimaryKey);
2714
2701
  model = newModel;
2715
2702
  }
2716
2703
 
@@ -2734,7 +2721,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
2734
2721
  let dirtyField = dirtyFields[i];
2735
2722
  let fieldValue = modelChanges[dirtyField.fieldName].current;
2736
2723
  let escapedColumnName = this.getEscapedColumnName(dirtyField.Model, dirtyField.columnName, { columnNameOnly: true });
2737
- let escapedValue = (LiteralBase.isLiteral(fieldValue)) ? fieldValue.toString(this.connection) : this.escape(dirtyField, fieldValue);
2724
+ let escapedValue = (LiteralBase.isLiteral(fieldValue)) ? fieldValue.toString(this.connection, { as: false }) : this.escape(dirtyField, fieldValue);
2738
2725
  if (!escapedValue)
2739
2726
  continue;
2740
2727
 
@@ -3364,7 +3351,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
3364
3351
  let newDefaultValue = this.getFieldDefaultValue(newField, newField.fieldName, { useDefaultKeyword: false, escape: true, remoteOnly: true });
3365
3352
 
3366
3353
  let currentFieldType = field.type.toConnectionType(this.connection, { createTable: true, defaultValue: currentDefaultValue });
3367
- let newFieldType = field.type.toConnectionType(this.connection, { createTable: true, defaultValue: newDefaultValue });
3354
+ let newFieldType = newField.type.toConnectionType(this.connection, { createTable: true, defaultValue: newDefaultValue });
3368
3355
  if (newFieldType !== currentFieldType)
3369
3356
  statements.push(this.generateAlterColumnChangeTypeStatement(field, newField, newFieldType, _options));
3370
3357
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm-sql-base",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "SQL base support for Mythix ORM",
5
5
  "main": "lib/index",
6
6
  "type": "commonjs",
@@ -34,18 +34,18 @@
34
34
  },
35
35
  "homepage": "https://github.com/th317erd/mythix-orm-sql-base#readme",
36
36
  "peerDependencies": {
37
- "mythix-orm": "^1.13.2"
37
+ "mythix-orm": "^1.14.0"
38
38
  },
39
39
  "dependencies": {
40
- "luxon": "^3.1.0",
40
+ "luxon": "^3.2.1",
41
41
  "nife": "^1.12.1",
42
42
  "sqlstring": "^2.3.3",
43
43
  "uuid": "^9.0.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
47
- "better-sqlite3": "^8.0.0",
48
- "eslint": "^8.28.0",
47
+ "better-sqlite3": "^8.0.1",
48
+ "eslint": "^8.31.0",
49
49
  "jasmine": "^4.5.0",
50
50
  "nyc": "^15.1.0"
51
51
  },