mythix-orm 1.13.2 → 1.13.3

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
 
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "description": "ORM for Mythix framework",
5
5
  "main": "lib/index",
6
6
  "type": "commonjs",