@onyx.dev/onyx-database 0.1.6 → 0.1.9

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
@@ -182,7 +182,7 @@ export interface UserProfile {
182
182
 
183
183
  const user = await db
184
184
  .from(tables.User)
185
- .selectFields('id', 'username')
185
+ .select('id', 'username')
186
186
  .resolve('roles.permissions', 'profile')
187
187
  .firstOrNull();
188
188
 
package/dist/index.cjs CHANGED
@@ -582,13 +582,36 @@ var QueryResults = class extends Array {
582
582
  /**
583
583
  * Iterates over each record on the current page only.
584
584
  * @param action - Function to invoke for each record.
585
+ * @param thisArg - Optional `this` binding for the callback.
585
586
  * @example
586
587
  * ```ts
587
588
  * results.forEachOnPage(u => console.log(u.id));
588
589
  * ```
589
590
  */
590
- forEachOnPage(action) {
591
- this.forEach(action);
591
+ forEachOnPage(action, thisArg) {
592
+ super.forEach((value, index) => {
593
+ action.call(thisArg, value, index, this);
594
+ });
595
+ }
596
+ /**
597
+ * Iterates over every record across all pages sequentially.
598
+ * @param action - Function executed for each record. Returning `false`
599
+ * stops iteration early.
600
+ * @param thisArg - Optional `this` binding for the callback.
601
+ * @example
602
+ * ```ts
603
+ * await results.forEach(u => {
604
+ * console.log(u.id);
605
+ * });
606
+ * ```
607
+ */
608
+ forEach(action, thisArg) {
609
+ let index = 0;
610
+ return this.forEachAll(async (item) => {
611
+ const result = await action.call(thisArg, item, index, this);
612
+ index += 1;
613
+ return result;
614
+ });
592
615
  }
593
616
  /**
594
617
  * Iterates over every record across all pages sequentially.
@@ -982,7 +1005,7 @@ var OnyxDatabaseImpl = class {
982
1005
  null,
983
1006
  this.defaultPartition
984
1007
  );
985
- qb.selectFields(...fields);
1008
+ qb.select(...fields);
986
1009
  return qb;
987
1010
  }
988
1011
  cascade(...relationships) {
@@ -1189,7 +1212,7 @@ var QueryBuilderImpl = class {
1189
1212
  this.table = table;
1190
1213
  return this;
1191
1214
  }
1192
- selectFields(...fields) {
1215
+ select(...fields) {
1193
1216
  const flat = fields.flatMap((f) => Array.isArray(f) ? f : [f]);
1194
1217
  this.fields = flat.length > 0 ? flat : null;
1195
1218
  return this;