mythix-orm 1.13.2 → 1.14.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/README.md CHANGED
@@ -99,7 +99,7 @@ class User extends Model {
99
99
 
100
100
  ## Notes
101
101
 
102
- 1. The [WIKI](https://github.com/th317erd/mythix-orm/wiki) is still being worked on. Most of the documentation is complete, but there is still a lot more to write. Documentation is the main focus right now. If you have any questions, feel free to drop a line, or open an issue! We will be happy to answer any questions. We aren't "done" until our documentation is pristine.
102
+ 1. The [WIKI](https://github.com/th317erd/mythix-orm/wiki) is still being worked on. Most of the documentation is complete, but there is still a lot more to write. Documentation is the main focus right now. If you have any questions, feel free to drop a line, or open an issue! We will be happy to answer any questions. We aren't "done" until our documentation is pristine. Feel free to drop us a line in our [Discord](https://discord.gg/DZsAYvym9N) server if you need assistance.
103
103
  2. Right now there are only database drivers for [SQLite](https://www.npmjs.com/package/mythix-orm-sqlite) and [PostgreSQL](https://www.npmjs.com/package/mythix-orm-postgresql). More are planned, with a Mongo driver likely to land next, followed by MySQL. Help wanted!
104
104
  3. Check out the [Mythix](https://www.npmjs.com/package/mythix) web-app framework. It is also still in active development, and the documentation is poor (to say the least), but it is up and coming, and will soon have fantastic documentation, and even though still in active development is fully functional. To get started try `npx mythix-cli create 'Test App'`
105
105
 
@@ -74,8 +74,6 @@ declare class ConnectionBase extends EventEmitter {
74
74
  public constructor(options?: ConnectionBaseOptions);
75
75
  public getLockMode(options: string | LockModeOptions): LockMode;
76
76
  public getDefaultOrder(Model: ModelClass, options?: GenericObject): Array<string>;
77
- public isLimitSupportedInContext(options?: GenericObject): boolean;
78
- public isOrderSupportedInContext(options?: GenericObject): boolean | string;
79
77
  public _getFromModelCache(Model: ModelClass, key: string, defaultValue?: any): any;
80
78
  public _setToModelCache<T>(Model: ModelClass, key: string, value: T): T;
81
79
  public getOptions(): ConnectionBaseOptions;
@@ -402,46 +402,6 @@ class ConnectionBase extends EventEmitter {
402
402
  getDefaultOrder(Model, options) {
403
403
  }
404
404
 
405
- /// This method is called (and often provided)
406
- /// by the underlying database driver to see
407
- /// if a `LIMIT` clause is allowed to appear in
408
- /// a given context/operation.
409
- ///
410
- /// Arguments:
411
- /// options: object
412
- /// Driver specific options for the context.
413
- ///
414
- /// Return: boolean
415
- isLimitSupportedInContext(options) {
416
- return true;
417
- }
418
-
419
- /// This method is called (and often provided)
420
- /// by the underlying database driver to see
421
- /// if an `ORDER BY` clause is allowed to appear in
422
- /// a given context/operation.
423
- ///
424
- /// Arguments:
425
- /// options: object
426
- /// Driver specific options for the context.
427
- ///
428
- /// Return: boolean
429
- isOrderSupportedInContext(_options) {
430
- let options = _options || {};
431
- if (options.isSubQuery) {
432
- let subQueryOperator = options.subQueryOperator;
433
- if (subQueryOperator === 'EXISTS' || subQueryOperator === 'NOT EXISTS')
434
- return false;
435
-
436
- if (subQueryOperator === 'ANY' || subQueryOperator === 'ALL')
437
- return true;
438
-
439
- return 'PROJECTION_ONLY';
440
- }
441
-
442
- return true;
443
- }
444
-
445
405
  /// A convenience method to get from "model cache".
446
406
  ///
447
407
  /// Model Cache is a simple system to cache
@@ -2640,12 +2600,7 @@ class ConnectionBase extends EventEmitter {
2640
2600
  /// This allows the caller of an operation such as `insert`, or `update` to
2641
2601
  /// request that specific hooks not be called.
2642
2602
  async runSaveHooks(Model, models, operationHookName, saveHookName, _options) {
2643
- const throwError = (error) => {
2644
- throw error;
2645
- };
2646
-
2647
2603
  let options = _options || {};
2648
- let promises = [];
2649
2604
  let context = { connection: this, Model, options, self: null };
2650
2605
  let skipHooks = options.skipHooks;
2651
2606
 
@@ -2665,21 +2620,13 @@ class ConnectionBase extends EventEmitter {
2665
2620
  for (let i = 0, il = models.length; i < il; i++) {
2666
2621
  let model = models[i];
2667
2622
  let modelContext = { ...context, self: model };
2623
+ let result = (shouldSkipHook(operationHookName)) ? undefined : model[operationHookName](modelContext);
2668
2624
 
2669
- let promise = (shouldSkipHook(operationHookName)) ? undefined : model[operationHookName](modelContext);
2670
- if (!Nife.instanceOf(promise, 'promise'))
2671
- promise = Promise.resolve(promise);
2625
+ await result;
2672
2626
 
2673
- if (!shouldSkipHook(saveHookName)) {
2674
- promise = promise.then(async () => await model[saveHookName](modelContext), throwError);
2675
- if (!Nife.instanceOf(promise, 'promise'))
2676
- promise = Promise.resolve(promise);
2677
- }
2678
-
2679
- promises.push(promise);
2627
+ if (!shouldSkipHook(saveHookName))
2628
+ await model[saveHookName](modelContext);
2680
2629
  }
2681
-
2682
- await Promise.all(promises);
2683
2630
  }
2684
2631
 
2685
2632
  /// Drop a table/bucket from the database.
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const Nife = require('nife');
4
+
3
5
  /// The base query generator class.
4
6
  ///
5
7
  /// A "query generator" is an interface that will take
@@ -339,6 +341,69 @@ class QueryGeneratorBase {
339
341
  // eslint-disable-next-line no-unused-vars
340
342
  getFieldDefaultValue(field, fieldName, _options) {
341
343
  }
344
+
345
+ /// Take a <see>Field</see> instance, and generate
346
+ /// all index fields for this `field`.
347
+ ///
348
+ /// The `index` property on a <see>Field</see> is used
349
+ /// to generate indexes for the field. If a `true` value
350
+ /// is encountered in the `index`, it means "this field".
351
+ /// If another field name is encountered in the `index` property,
352
+ /// then that means "combine this field with the specified field"
353
+ /// (to create a combined index). Take the following example:
354
+ /// ```javascript
355
+ /// ...
356
+ /// firstName: {
357
+ /// ...
358
+ /// index: [
359
+ /// true,
360
+ /// 'lastName',
361
+ /// [ 'email', 'lastName' ],
362
+ /// ]
363
+ /// }
364
+ /// ...
365
+ /// ```
366
+ /// This will create three indexes for this "firstName" column in the database:
367
+ /// 1) `true` = Index the `firstName` column by itself (`idx_users_firstName`)
368
+ /// 2) `lastName` = Combine `firstName` and `lastName` to create a combined index (`idx_users_firstName_lastName`)
369
+ /// 3) `[ 'email', 'lastName' ]` = Combine `firstName` with `email` and `lastName` to create a combined index involving three columns (`idx_users_firstName_email_lastName`)
370
+ /// Using the above example, this method would return the following:
371
+ /// ```javascript
372
+ /// [
373
+ /// [ 'firstName' ],
374
+ /// [ 'firstName', 'lastName' ],
375
+ /// [ 'firstName', 'email', 'lastName' ],
376
+ /// ]
377
+ /// ```
378
+ /// Which is the list of indexes, and the fields to index for each index.
379
+ ///
380
+ /// Arguments:
381
+ /// field: <see>Field</see>
382
+ /// The field used to pull the `index` property from.
383
+ ///
384
+ /// Return: Array<Array<string>>
385
+ /// Return an array of arrays, where the top-level array lists the
386
+ /// indexes, and each sub-array lists the fields to combine into an
387
+ /// index.
388
+ getIndexFieldsFromFieldIndex(field) {
389
+ let indexes = Nife.toArray(field.index).filter((index) => {
390
+ if (index === true)
391
+ return true;
392
+
393
+ return (Nife.instanceOf(index, 'string', 'array') && Nife.isNotEmpty(index));
394
+ });
395
+
396
+ if (indexes.length === 0)
397
+ return [];
398
+
399
+ return indexes.map((indexNames) => {
400
+ let fieldIndexNames = [ field.fieldName ];
401
+ if (indexNames !== true)
402
+ fieldIndexNames = fieldIndexNames.concat(indexNames);
403
+
404
+ return fieldIndexNames;
405
+ });
406
+ }
342
407
  }
343
408
 
344
409
  module.exports = QueryGeneratorBase;
package/lib/model.js CHANGED
@@ -7,6 +7,7 @@ const DefaultHelpers = require('./types/helpers/default-helpers');
7
7
  const Field = require('./field');
8
8
  const AsyncStore = require('./utils/async-store');
9
9
  const ModelUtils = require('./utils/model-utils');
10
+ const { LiteralBase } = require('./connection/literals');
10
11
 
11
12
  /// Used as a unique key for cache.
12
13
  /// Caches will generally be stored in
@@ -2188,6 +2189,9 @@ class Model {
2188
2189
  if (!type)
2189
2190
  return value;
2190
2191
 
2192
+ if (LiteralBase.isLiteral(value))
2193
+ return value;
2194
+
2191
2195
  return type.castToType({
2192
2196
  connection: this.getConnection(),
2193
2197
  Model: this.getModel(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "description": "ORM for Mythix framework",
5
5
  "main": "lib/index",
6
6
  "type": "commonjs",
@@ -34,18 +34,18 @@
34
34
  "homepage": "https://github.com/th317erd/mythix-orm#readme",
35
35
  "devDependencies": {
36
36
  "@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
37
- "@types/node": "^18.11.9",
38
- "better-sqlite3": "^8.0.0",
37
+ "@types/node": "^18.11.18",
38
+ "better-sqlite3": "^8.0.1",
39
39
  "colors": "^1.4.0",
40
40
  "diff": "^5.1.0",
41
- "eslint": "^8.28.0",
41
+ "eslint": "^8.31.0",
42
42
  "jasmine": "^4.5.0",
43
43
  "nyc": "^15.1.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "events": "^3.3.0",
47
- "inflection": "^2.0.0",
48
- "luxon": "^3.1.0",
47
+ "inflection": "^2.0.1",
48
+ "luxon": "^3.2.1",
49
49
  "nife": "^1.12.1",
50
50
  "uuid": "^9.0.0",
51
51
  "xid-js": "^1.0.1"