masterrecord 1.3.2 → 1.3.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/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # MasterRecord Changelog
2
2
 
3
+ ## v1.3.3 — `.toList()` no longer silently caps at 1000 rows
4
+
5
+ **Bug (high — silent data loss):** `.toList()` injected a default `LIMIT 1000` whenever the caller hadn't chained `.take()`. Any query matching more than 1000 rows silently returned only the first 1000 — no error, no warning, undocumented. Aggregates derived from the result (counts, sums, "does X exist?") were silently wrong. The cap was also gated on `entityMap.length === 0`, so an `.include()` query was **not** capped while the same query without an include **was** — identical-looking calls behaved differently. (EF/LINQ's `ToList()`, which this API mirrors, returns everything.)
6
+
7
+ **Fix:**
8
+ - Removed the implicit cap in `toList()` — it now returns **all** matching rows. `.take(n)` still limits explicitly, and `.include()` / non-include queries now behave identically.
9
+ - Removing the cap exposed a latent bug it had been masking: SQLite and MySQL reject a bare `OFFSET` with no `LIMIT`, so `.skip()` **without** `.take()` would have produced invalid SQL. `buildSkip()` now emits valid pagination on every engine:
10
+ - **SQLite** — `LIMIT -1 OFFSET n` (`-1` = no upper bound)
11
+ - **MySQL** — `LIMIT 18446744073709551615 OFFSET n` (max `BIGINT UNSIGNED`, the documented "all rows from offset" sentinel)
12
+ - **Postgres** — `OFFSET n` (a bare `OFFSET` is already valid; left as-is)
13
+
14
+ New test: `test/tolist-no-implicit-limit.test.js` — SQLite executes 1500-row `toList()` (returns all), `where().toList()` (> 1000), `.take()` still limits, bare `.skip()` pages to the end, `.skip().take()` windows; plus `buildSkip()` SQL-shape assertions for all three engines. A gated cross-engine integration test seeds 1500 rows and asserts `toList()`/bare-`.skip()` against live MySQL/Postgres. Full suite green (0 fail); 0 lint errors.
15
+
3
16
  ## v1.3.2 — migration CLI auto-creates a missing MySQL/Postgres database
4
17
 
5
18
  **Bug (critical for first deploys):** `update-database` printed *"Instantiating Context (this will create the database if it doesn't exist)…"*, but it `await`ed the raw `context._initPromise` directly. When the target database didn't exist, that promise rejected with `Unknown database 'X'` (MySQL) / `database "X" does not exist` (Postgres), and the catch block merely reported failure and exited — it **never invoked the auto-create** (`_createDatabaseFromConfig` + retry) that lives in `schema._ensureReady()`. So a first-time deploy against an empty server failed with a confusing error despite the CLI claiming it would create the database. (Confirmed present through 1.3.1.)
@@ -534,9 +534,6 @@ class queryMethods{
534
534
  async toList(){
535
535
  if(this.__queryObject.script.entityMap.length === 0){
536
536
  this.__queryObject.skipClause( this.__entity.__name);
537
- if(!this.__queryObject.script.take || this.__queryObject.script.take === 0){
538
- this.__queryObject.script.take = 1000;
539
- }
540
537
  }
541
538
 
542
539
  // Generate cache key
package/SQLLiteEngine.js CHANGED
@@ -374,7 +374,12 @@ class SQLLiteEngine {
374
374
 
375
375
  buildSkip(query){
376
376
  if(query.skip){
377
- return `OFFSET ${query.skip}`
377
+ // SQLite requires a LIMIT before OFFSET. When the caller paginated
378
+ // with .skip() but no .take(), emit `LIMIT -1` (SQLite's documented
379
+ // "no upper bound") so the OFFSET is valid SQL instead of a syntax
380
+ // error. Now that .toList() no longer injects a default LIMIT 1000,
381
+ // this is the path a bare .skip() takes.
382
+ return query.take ? `OFFSET ${query.skip}` : `LIMIT -1 OFFSET ${query.skip}`;
378
383
  }
379
384
  else{
380
385
  return "";
@@ -54,7 +54,7 @@ context.User.where(u => $$.includes(u.id), [1, 2, 3]).toList();
54
54
  | `.take(n)` | Limit results | `.take(10)` |
55
55
  | `.skip(n)` | Offset results | `.skip(20)` |
56
56
  | `.search({ in, query })` | Full-text search (see [FULL_TEXT_SEARCH.md](FULL_TEXT_SEARCH.md)) | `context.MemoryDoc.search({ in: ['title','body'], query: 'auth login' })` |
57
- | `.toList()` | Execute and return array | `.where(...).toList()` |
57
+ | `.toList()` | Execute and return **all** matching rows as an array (no implicit limit — use `.take(n)`/`.skip(n)` to page) | `.where(...).toList()` |
58
58
  | `.single()` | Execute and return one | `.where(...).single()` |
59
59
  | `.first()` | Execute and return first | `.where(...).first()` |
60
60
  | `.include(lambda)` | Eager load relationships | `.include(u => u.Posts)` |
package/mySQLEngine.js CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
5
5
  "type": "module",
6
6
  "main": "./MasterRecord.js",
package/postgresEngine.js CHANGED
@@ -611,6 +611,8 @@ class postgresEngine {
611
611
 
612
612
  buildSkip(query) {
613
613
  if (query.skip) {
614
+ // Unlike SQLite/MySQL, Postgres accepts a bare OFFSET with no LIMIT,
615
+ // so a .skip() without .take() is valid as-is — no sentinel needed.
614
616
  return `OFFSET ${query.skip}`;
615
617
  }
616
618
  return "";
package/readme.md CHANGED
@@ -636,6 +636,10 @@ const users = await db.User
636
636
 
637
637
  ### Pagination
638
638
 
639
+ `.toList()` returns **all** matching rows — there is no implicit row limit (it
640
+ mirrors EF/LINQ `ToList()`). Use `.take(n)` to cap results and `.skip(n)` to
641
+ offset; a bare `.skip(n)` with no `.take()` pages to the end of the result set.
642
+
639
643
  ```javascript
640
644
  // Skip 20, take 10 (requires await)
641
645
  const users = await db.User
@@ -651,6 +655,12 @@ const users = await db.User
651
655
  .skip(page * pageSize)
652
656
  .take(pageSize)
653
657
  .toList();
658
+
659
+ // Everything after an offset (no upper bound)
660
+ const rest = await db.User.orderBy(u => u.id).skip(100).toList();
661
+
662
+ // Every row (no limit)
663
+ const everyone = await db.User.toList();
654
664
  ```
655
665
 
656
666
  ### Counting