foxhound 2.0.26 → 2.0.28

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/docs/schema.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Schema Integration
2
2
 
3
- FoxHound is schema-aware when a schema array is attached to a query, it uses the column type annotations to automatically manage identity columns, timestamps, user stamps, and soft-delete tracking.
3
+ FoxHound is schema-aware -- when a schema array is attached to a query, it uses the column type annotations to automatically manage identity columns, timestamps, user stamps, and soft-delete tracking.
4
4
 
5
5
  ## Attaching a Schema
6
6
 
@@ -29,22 +29,22 @@ tmpQuery.query.schema = [
29
29
 
30
30
  | Type | Purpose | Create | Read | Update | Delete | Undelete |
31
31
  |------|---------|--------|------|--------|--------|----------|
32
- | `AutoIdentity` | Auto-increment primary key | `NULL` (DB assigns) | included | **skipped** | | |
33
- | `AutoGUID` | Auto-generated UUID | UUID or user value | included | included | | |
34
- | `CreateDate` | Row creation timestamp | `NOW()` | included | **skipped** | | |
35
- | `CreateIDUser` | Row creator user ID | `IDUser` | included | **skipped** | | |
32
+ | `AutoIdentity` | Auto-increment primary key | `NULL` (DB assigns) | included | **skipped** | -- | -- |
33
+ | `AutoGUID` | Auto-generated UUID | UUID or user value | included | included | -- | -- |
34
+ | `CreateDate` | Row creation timestamp | `NOW()` | included | **skipped** | -- | -- |
35
+ | `CreateIDUser` | Row creator user ID | `IDUser` | included | **skipped** | -- | -- |
36
36
  | `UpdateDate` | Last modification timestamp | `NOW()` | included | `NOW()` | `NOW()` | `NOW()` |
37
- | `UpdateIDUser` | Last modifier user ID | `IDUser` | included | `IDUser` | | `IDUser` |
38
- | `Deleted` | Soft-delete flag | `0` | auto-filtered | | set to `1` | set to `0` |
39
- | `DeleteDate` | Deletion timestamp | **skipped** | included | **skipped** | `NOW()` | |
40
- | `DeleteIDUser` | Deleter user ID | **skipped** | included | **skipped** | `IDUser` | |
41
- | `String` | Text data | parameterized | included | parameterized | | |
42
- | `Integer` | Numeric data | parameterized | included | parameterized | | |
43
- | `Decimal` | Decimal data | parameterized | included | parameterized | | |
44
- | `Boolean` | Boolean data | parameterized | included | parameterized | | |
45
- | `DateTime` | Date/time data | parameterized | included | parameterized | | |
46
- | `JSON` | Structured JSON data | `JSON.stringify` | included | `JSON.stringify` | | |
47
- | `JSONProxy` | JSON with different SQL column name | `JSON.stringify` to `StorageColumn` | included | `JSON.stringify` to `StorageColumn` | | |
37
+ | `UpdateIDUser` | Last modifier user ID | `IDUser` | included | `IDUser` | -- | `IDUser` |
38
+ | `Deleted` | Soft-delete flag | `0` | auto-filtered | -- | set to `1` | set to `0` |
39
+ | `DeleteDate` | Deletion timestamp | **skipped** | included | **skipped** | `NOW()` | -- |
40
+ | `DeleteIDUser` | Deleter user ID | **skipped** | included | **skipped** | `IDUser` | -- |
41
+ | `String` | Text data | parameterized | included | parameterized | -- | -- |
42
+ | `Integer` | Numeric data | parameterized | included | parameterized | -- | -- |
43
+ | `Decimal` | Decimal data | parameterized | included | parameterized | -- | -- |
44
+ | `Boolean` | Boolean data | parameterized | included | parameterized | -- | -- |
45
+ | `DateTime` | Date/time data | parameterized | included | parameterized | -- | -- |
46
+ | `JSON` | Structured JSON data | `JSON.stringify` | included | `JSON.stringify` | -- | -- |
47
+ | `JSONProxy` | JSON with different SQL column name | `JSON.stringify` to `StorageColumn` | included | `JSON.stringify` to `StorageColumn` | -- | -- |
48
48
 
49
49
  ## JSON and JSON Proxy Types
50
50
 
@@ -99,33 +99,33 @@ Nested paths are supported (e.g., `Metadata.dimensions.width`). JSON Proxy colum
99
99
 
100
100
  ### Create (INSERT)
101
101
 
102
- - `AutoIdentity` inserts `NULL` (MySQL/SQLite) or is omitted (MSSQL)
103
- - `AutoGUID` generates a UUID via Fable, unless the record has a valid GUID already
104
- - `CreateDate`, `UpdateDate` inserts the current timestamp
105
- - `CreateIDUser`, `UpdateIDUser` inserts the user ID from `setIDUser()`
106
- - `DeleteDate`, `DeleteIDUser` **skipped** (when delete tracking is enabled)
102
+ - `AutoIdentity` -> inserts `NULL` (MySQL/SQLite) or is omitted (MSSQL)
103
+ - `AutoGUID` -> generates a UUID via Fable, unless the record has a valid GUID already
104
+ - `CreateDate`, `UpdateDate` -> inserts the current timestamp
105
+ - `CreateIDUser`, `UpdateIDUser` -> inserts the user ID from `setIDUser()`
106
+ - `DeleteDate`, `DeleteIDUser` -> **skipped** (when delete tracking is enabled)
107
107
 
108
108
  ### Update
109
109
 
110
- - `AutoIdentity`, `CreateDate`, `CreateIDUser`, `DeleteDate`, `DeleteIDUser` **skipped**
111
- - `UpdateDate` set to current timestamp automatically
112
- - `UpdateIDUser` set to the value from `setIDUser()`
113
- - All other columns parameterized from the record
110
+ - `AutoIdentity`, `CreateDate`, `CreateIDUser`, `DeleteDate`, `DeleteIDUser` -> **skipped**
111
+ - `UpdateDate` -> set to current timestamp automatically
112
+ - `UpdateIDUser` -> set to the value from `setIDUser()`
113
+ - All other columns -> parameterized from the record
114
114
 
115
115
  ### Delete (Soft)
116
116
 
117
117
  Only these columns are modified:
118
- - `Deleted` set to `1`
119
- - `DeleteDate` set to current timestamp
120
- - `UpdateDate` set to current timestamp
121
- - `DeleteIDUser` set to the value from `setIDUser()`
118
+ - `Deleted` -> set to `1`
119
+ - `DeleteDate` -> set to current timestamp
120
+ - `UpdateDate` -> set to current timestamp
121
+ - `DeleteIDUser` -> set to the value from `setIDUser()`
122
122
 
123
123
  ### Undelete
124
124
 
125
125
  Only these columns are modified:
126
- - `Deleted` set to `0`
127
- - `UpdateDate` set to current timestamp
128
- - `UpdateIDUser` set to the value from `setIDUser()`
126
+ - `Deleted` -> set to `0`
127
+ - `UpdateDate` -> set to current timestamp
128
+ - `UpdateIDUser` -> set to the value from `setIDUser()`
129
129
 
130
130
  ### Read / Count
131
131
 
@@ -143,4 +143,4 @@ Only these columns are modified:
143
143
 
144
144
  ## Stricture Integration
145
145
 
146
- Schemas are typically defined using [Stricture](https://github.com/stevenvelozo/stricture), a companion tool that generates schema definitions from a DDL-like JSON format. Stricture produces the exact schema array format that FoxHound expects.
146
+ Schemas are typically defined using [Stricture](https://github.com/fable-retold/stricture), a companion tool that generates schema definitions from a DDL-like JSON format. Stricture produces the exact schema array format that FoxHound expects.
package/docs/sorting.md CHANGED
@@ -33,7 +33,7 @@ tmpQuery
33
33
  // ORDER BY Genre, PublishedYear DESC
34
34
  ```
35
35
 
36
- Columns without an explicit `Direction` (or with `Direction: 'Ascending'`) sort in ascending order the SQL default.
36
+ Columns without an explicit `Direction` (or with `Direction: 'Ascending'`) sort in ascending order -- the SQL default.
37
37
 
38
38
  ## Setting Sorts Directly
39
39
 
@@ -71,9 +71,9 @@ tmpQuery.setSort({Column: 'Title', Direction: 'Descending'});
71
71
 
72
72
  The `ORDER BY` clause syntax is consistent across all SQL dialects. The main difference is in identifier quoting:
73
73
 
74
- - **MySQL** `ORDER BY PublishedYear DESC`
75
- - **MSSQL** `ORDER BY [PublishedYear] DESC`
76
- - **SQLite/ALASQL** `ORDER BY \`PublishedYear\` DESC`
74
+ - **MySQL** -- `ORDER BY PublishedYear DESC`
75
+ - **MSSQL** -- `ORDER BY [PublishedYear] DESC`
76
+ - **SQLite/ALASQL** -- `ORDER BY \`PublishedYear\` DESC`
77
77
 
78
78
  ## Interaction with Pagination
79
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxhound",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
37
- "url": "https://github.com/stevenvelozo/foxhound.git"
37
+ "url": "https://github.com/fable-retold/foxhound.git"
38
38
  },
39
39
  "keywords": [
40
40
  "orm",
@@ -44,14 +44,15 @@
44
44
  "author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
45
45
  "license": "MIT",
46
46
  "bugs": {
47
- "url": "https://github.com/stevenvelozo/foxhound/issues"
47
+ "url": "https://github.com/fable-retold/foxhound/issues"
48
48
  },
49
- "homepage": "https://github.com/stevenvelozo/foxhound",
49
+ "homepage": "https://github.com/fable-retold/foxhound",
50
50
  "devDependencies": {
51
- "quackage": "^1.0.63"
51
+ "pict-docuserve": "^1.4.12",
52
+ "quackage": "^1.3.0"
52
53
  },
53
54
  "dependencies": {
54
- "fable": "^3.1.63",
55
+ "fable": "^3.1.75",
55
56
  "typescript": "^5.9.3"
56
57
  }
57
58
  }
@@ -9,6 +9,7 @@ let getDialects = () =>
9
9
  tmpDialects.MySQL = require('./dialects/MySQL/FoxHound-Dialect-MySQL.js');
10
10
  tmpDialects.MSSQL = require('./dialects/MicrosoftSQL/FoxHound-Dialect-MSSQL.js');
11
11
  tmpDialects.PostgreSQL = require('./dialects/PostgreSQL/FoxHound-Dialect-PostgreSQL.js');
12
+ tmpDialects.Oracle = require('./dialects/Oracle/FoxHound-Dialect-Oracle.js');
12
13
  tmpDialects.MongoDB = require('./dialects/MongoDB/FoxHound-Dialect-MongoDB.js');
13
14
  tmpDialects.DGraph = require('./dialects/DGraph/FoxHound-Dialect-DGraph.js');
14
15
  tmpDialects.Solr = require('./dialects/Solr/FoxHound-Dialect-Solr.js');
@@ -179,6 +179,51 @@ var FoxHoundDialectMSSQL = function(pFable)
179
179
  return tmpFieldList;
180
180
  };
181
181
 
182
+ /**
183
+ * Generate a field list for the outer SELECT of the legacy pagination
184
+ * wrapper. The outer FROM is a subquery aliased as [_Paged], so the
185
+ * default "[Table].*" qualifier can't resolve there — we need either
186
+ * an explicit column list from the schema or a bare "*".
187
+ *
188
+ * If the caller set explicit dataElements, reuse them (they reference
189
+ * bare column names, which work fine against the subquery alias).
190
+ * Otherwise emit an explicit list from the schema to keep [_RowNum]
191
+ * from leaking. As a last resort, fall back to "*" — callers without
192
+ * a schema will see [_RowNum] as an extra property on marshalled
193
+ * records but the query itself remains valid.
194
+ *
195
+ * @param: {Object} pParameters SQL Query Parameters
196
+ * @return: {String} Field list (prefixed with a single leading space)
197
+ */
198
+ var generateOuterFieldListForLegacyPagination = function(pParameters)
199
+ {
200
+ var tmpDataElements = pParameters.dataElements;
201
+ if (Array.isArray(tmpDataElements) && tmpDataElements.length > 0)
202
+ {
203
+ // Reuse the caller-supplied list. It emits unqualified column
204
+ // names ([Col], [Col] AS [Alias]) which resolve fine against
205
+ // the subquery alias.
206
+ return generateFieldList(pParameters);
207
+ }
208
+
209
+ var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
210
+ if (tmpSchema.length > 0)
211
+ {
212
+ var tmpList = ' ';
213
+ for (var i = 0; i < tmpSchema.length; i++)
214
+ {
215
+ if (i > 0) tmpList += ', ';
216
+ tmpList += generateSafeFieldName(tmpSchema[i].Column);
217
+ }
218
+ return tmpList;
219
+ }
220
+
221
+ // No schema, no explicit dataElements — "*" is the best we can do.
222
+ // [_RowNum] will surface on marshalled records; downstream code can
223
+ // ignore it. Schemas are the norm via Meadow so this is rare.
224
+ return ' *';
225
+ };
226
+
182
227
  /**
183
228
  * Ensure a field name is properly escaped.
184
229
  */
@@ -352,12 +397,41 @@ var FoxHoundDialectMSSQL = function(pFable)
352
397
  return tmpWhere;
353
398
  };
354
399
 
400
+ /**
401
+ * Find the table's AutoIdentity primary-key column from the schema, if any.
402
+ * Used as a deterministic default ORDER BY when the caller didn't set a
403
+ * sort — MSSQL pagination (both OFFSET/FETCH and ROW_NUMBER) requires an
404
+ * ORDER BY clause or it produces a syntax error.
405
+ *
406
+ * @param: {Object} pParameters SQL Query Parameters
407
+ * @return: {String|null} The column name, or null if none found
408
+ */
409
+ var findPrimaryKeyColumn = function(pParameters)
410
+ {
411
+ var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
412
+ for (var i = 0; i < tmpSchema.length; i++)
413
+ {
414
+ if (tmpSchema[i].Type === 'AutoIdentity')
415
+ {
416
+ return tmpSchema[i].Column;
417
+ }
418
+ }
419
+ return null;
420
+ };
421
+
355
422
  /**
356
423
  * Generate an ORDER BY clause from the sort array
357
424
  *
358
425
  * Each entry in the sort is an object like:
359
426
  * {Column:'Color',Direction:'Descending'}
360
427
  *
428
+ * When no sort is specified but the query has a cap (pagination is
429
+ * active), inject a default ORDER BY on the primary key so MSSQL
430
+ * doesn't reject the OFFSET/FETCH or ROW_NUMBER clause. Without a
431
+ * schema the PK can't be inferred — fall back to `ORDER BY (SELECT 1)`
432
+ * which is legal for OFFSET/FETCH but not for ROW_NUMBER (the legacy
433
+ * pagination path handles that case by refusing to paginate).
434
+ *
361
435
  * @method: generateOrderBy
362
436
  * @param: {Object} pParameters SQL Query Parameters
363
437
  * @return: {String} Returns the field list clause
@@ -367,6 +441,15 @@ var FoxHoundDialectMSSQL = function(pFable)
367
441
  var tmpOrderBy = pParameters.sort;
368
442
  if (!Array.isArray(tmpOrderBy) || tmpOrderBy.length < 1)
369
443
  {
444
+ if (pParameters.cap)
445
+ {
446
+ var tmpPK = findPrimaryKeyColumn(pParameters);
447
+ if (tmpPK)
448
+ {
449
+ return ' ORDER BY ['+tmpPK+']';
450
+ }
451
+ return ' ORDER BY (SELECT 1)';
452
+ }
370
453
  return '';
371
454
  }
372
455
 
@@ -390,6 +473,12 @@ var FoxHoundDialectMSSQL = function(pFable)
390
473
  /**
391
474
  * Generate the limit clause
392
475
  *
476
+ * When `legacyPagination` is set on pParameters the limit is emitted
477
+ * by the Read function using a ROW_NUMBER() subquery wrapper instead
478
+ * (OFFSET/FETCH NEXT requires SQL Server 2012+ / compatibility level
479
+ * 110+, which some customers don't have). In that case this function
480
+ * returns an empty string.
481
+ *
393
482
  * @method: generateLimit
394
483
  * @param: {Object} pParameters SQL Query Parameters
395
484
  * @return: {String} Returns the table limit clause
@@ -401,6 +490,13 @@ var FoxHoundDialectMSSQL = function(pFable)
401
490
  return '';
402
491
  }
403
492
 
493
+ if (pParameters.legacyPagination)
494
+ {
495
+ // The Read function wraps the query in a ROW_NUMBER() subquery
496
+ // instead of appending an OFFSET/FETCH tail clause.
497
+ return '';
498
+ }
499
+
404
500
  var tmpLimit = ' OFFSET ';
405
501
  // If there is a begin record, we'll pass that in as well.
406
502
  if (pParameters.begin !== false)
@@ -1037,6 +1133,30 @@ var FoxHoundDialectMSSQL = function(pFable)
1037
1133
  }
1038
1134
  }
1039
1135
 
1136
+ // Legacy pagination path — emit a ROW_NUMBER() wrapper instead of
1137
+ // OFFSET/FETCH. Required for SQL Server 2008 R2 and earlier, or
1138
+ // for databases running at a compatibility level below 110 (2012).
1139
+ // Enabled via pParameters.legacyPagination (forwarded from the
1140
+ // meadow-connection-mssql provider's LegacyPagination config).
1141
+ if (pParameters.legacyPagination && pParameters.cap)
1142
+ {
1143
+ var tmpBegin = (pParameters.begin !== false) ? pParameters.begin : 0;
1144
+ var tmpEnd = tmpBegin + pParameters.cap;
1145
+ // generateOrderBy always returns a usable ORDER BY when cap is
1146
+ // set. ROW_NUMBER()'s OVER() clause takes the same body but
1147
+ // without the leading space.
1148
+ var tmpOverClause = tmpOrderBy.replace(/^ /, '');
1149
+ // The outer SELECT's FROM is the subquery alias, not the base
1150
+ // table — so the default field list's "[Table].*" qualifier
1151
+ // won't resolve at the outer level. Compute an outer field
1152
+ // list that works regardless of whether the caller supplied
1153
+ // explicit dataElements or relied on the default.
1154
+ var tmpOuterFieldList = generateOuterFieldListForLegacyPagination(pParameters);
1155
+ // INDEX hints and JOINs live on the inner select (they apply
1156
+ // to the base table). [_RowNum] is confined to the subquery.
1157
+ return `SELECT${tmpOptDistinct}${tmpOuterFieldList} FROM (SELECT${tmpFieldList}, ROW_NUMBER() OVER (${tmpOverClause}) AS [_RowNum] FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere}) AS [_Paged] WHERE [_RowNum] > ${tmpBegin} AND [_RowNum] <= ${tmpEnd};`;
1158
+ }
1159
+
1040
1160
  return `SELECT${tmpOptDistinct}${tmpFieldList} FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere}${tmpOrderBy}${tmpLimit};`;
1041
1161
  };
1042
1162