@bunnykit/orm 0.1.16 → 0.1.17
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/dist/src/query/Builder.d.ts +1 -1
- package/dist/src/query/Builder.js +30 -24
- package/package.json +1 -1
|
@@ -160,7 +160,7 @@ export declare class Builder<T = Record<string, any>> {
|
|
|
160
160
|
paginate(perPage?: number, page?: number): Promise<Paginator<T>>;
|
|
161
161
|
chunk(count: number, callback: (items: T[]) => void | Promise<void>): Promise<void>;
|
|
162
162
|
each(count: number, callback: (item: T) => void | Promise<void>): Promise<void>;
|
|
163
|
-
cursor(
|
|
163
|
+
cursor(chunkSize?: number): AsyncGenerator<T>;
|
|
164
164
|
lazy(count?: number): AsyncGenerator<T>;
|
|
165
165
|
insert(data: ModelAttributeInput<T> | ModelAttributeInput<T>[]): Promise<any>;
|
|
166
166
|
insertGetId(data: ModelAttributeInput<T>, idColumn?: ModelColumn<T>): Promise<any>;
|
|
@@ -718,34 +718,40 @@ export class Builder {
|
|
|
718
718
|
}
|
|
719
719
|
});
|
|
720
720
|
}
|
|
721
|
-
async *cursor(
|
|
721
|
+
async *cursor(chunkSize = 1000) {
|
|
722
722
|
const model = this.model;
|
|
723
723
|
const primaryKey = model ? model.primaryKey || "id" : "id";
|
|
724
724
|
const orderColumn = this.orders[0]?.column || primaryKey;
|
|
725
725
|
const orderDirection = this.orders[0]?.direction || "asc";
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
builder.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
726
|
+
let lastValue = undefined;
|
|
727
|
+
while (true) {
|
|
728
|
+
const builder = this.clone();
|
|
729
|
+
builder.orders = [{ column: orderColumn, direction: orderDirection }];
|
|
730
|
+
builder.offsetValue = undefined;
|
|
731
|
+
builder.limitValue = chunkSize;
|
|
732
|
+
if (lastValue !== undefined) {
|
|
733
|
+
const op = orderDirection === "asc" ? ">" : "<";
|
|
734
|
+
builder.wheres.push({
|
|
735
|
+
type: "basic",
|
|
736
|
+
column: orderColumn,
|
|
737
|
+
operator: op,
|
|
738
|
+
value: lastValue,
|
|
739
|
+
boolean: "and",
|
|
740
|
+
scope: undefined,
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const items = await builder.get();
|
|
744
|
+
if (items.length === 0)
|
|
745
|
+
break;
|
|
746
|
+
for (const item of items) {
|
|
747
|
+
yield item;
|
|
748
|
+
}
|
|
749
|
+
if (items.length < chunkSize)
|
|
750
|
+
break;
|
|
751
|
+
const lastItem = items[items.length - 1];
|
|
752
|
+
lastValue = lastItem && typeof lastItem === "object"
|
|
753
|
+
? lastItem[orderColumn]
|
|
754
|
+
: undefined;
|
|
749
755
|
}
|
|
750
756
|
}
|
|
751
757
|
async *lazy(count = 1000) {
|
package/package.json
CHANGED