@ginger.io/beyonce
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -27,2 +27,4 @@ import { JayZ } from "@ginger.io/jay-z"; | ||
private variables; | ||
private scanIndexForward; | ||
private limit?; | ||
constructor(config: TableQueryParams<T> | GSIQueryParams<T>); | ||
@@ -38,2 +40,4 @@ where(attribute: KeysOf<T>, operator: Operator, value: any): this; | ||
andAttributeNotExists(name: KeysOf<T>): this; | ||
reverse(): this; | ||
maxRecordsToProcess(n: number): this; | ||
exec(): Promise<GroupedModels<T>>; | ||
@@ -40,0 +44,0 @@ private addCondition; |
@@ -21,2 +21,3 @@ "use strict"; | ||
this.variables = new Variables(); | ||
this.scanIndexForward = true; | ||
} | ||
@@ -65,2 +66,10 @@ where(attribute, operator, value) { | ||
} | ||
reverse() { | ||
this.scanIndexForward = false; | ||
return this; | ||
} | ||
maxRecordsToProcess(n) { | ||
this.limit = n; | ||
return this; | ||
} | ||
exec() { | ||
@@ -74,3 +83,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
items.push(...(response.Items || [])); | ||
if (response.LastEvaluatedKey !== undefined) { | ||
if (response.LastEvaluatedKey !== undefined && this.limit === undefined) { | ||
pendingQuery = db.query(this.build(response.LastEvaluatedKey)).promise(); | ||
@@ -116,2 +125,4 @@ } | ||
ExclusiveStartKey: lastEvaluatedKey, | ||
ScanIndexForward: this.scanIndexForward, | ||
Limit: this.limit, | ||
}; | ||
@@ -131,2 +142,4 @@ } | ||
ExclusiveStartKey: lastEvaluatedKey, | ||
ScanIndexForward: this.scanIndexForward, | ||
Limit: this.limit, | ||
}; | ||
@@ -133,0 +146,0 @@ } |
{ | ||
"name": "@ginger.io/beyonce", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -32,2 +32,4 @@ import { JayZ } from "@ginger.io/jay-z" | ||
private variables = new Variables() | ||
private scanIndexForward: boolean = true | ||
private limit?: number | ||
@@ -87,2 +89,12 @@ constructor(private config: TableQueryParams<T> | GSIQueryParams<T>) {} | ||
reverse(): this { | ||
this.scanIndexForward = false | ||
return this | ||
} | ||
maxRecordsToProcess(n: number): this { | ||
this.limit = n | ||
return this | ||
} | ||
async exec(): Promise<GroupedModels<T>> { | ||
@@ -99,3 +111,3 @@ const { db } = this.config | ||
if (response.LastEvaluatedKey !== undefined) { | ||
if (response.LastEvaluatedKey !== undefined && this.limit === undefined) { | ||
pendingQuery = db.query(this.build(response.LastEvaluatedKey)).promise() | ||
@@ -157,2 +169,4 @@ } else { | ||
ExclusiveStartKey: lastEvaluatedKey, | ||
ScanIndexForward: this.scanIndexForward, | ||
Limit: this.limit, | ||
} | ||
@@ -175,2 +189,4 @@ } else { | ||
ExclusiveStartKey: lastEvaluatedKey, | ||
ScanIndexForward: this.scanIndexForward, | ||
Limit: this.limit, | ||
} | ||
@@ -177,0 +193,0 @@ } |
@@ -54,2 +54,10 @@ import { JayZ, FixedDataKeyProvider } from "@ginger.io/jay-z" | ||
it("should set maxRecordsToProcess", async () => { | ||
await testQueryWithLimit() | ||
}) | ||
it("should find the highest sort key", async () => { | ||
await testQueryWithReverseAndLimit() | ||
}) | ||
// With JayZ encryption | ||
@@ -100,2 +108,12 @@ it("should put and retrieve an item using pk + sk with jayZ", async () => { | ||
}) | ||
it("should set maxRecordsToProcess with JayZ", async () => { | ||
const jayZ = await createJayZ() | ||
await testQueryWithLimit(jayZ) | ||
}) | ||
it("should find the highest sort key with JayZ", async () => { | ||
const jayZ = await createJayZ() | ||
await testQueryWithReverseAndLimit(jayZ) | ||
}) | ||
}) | ||
@@ -176,2 +194,29 @@ | ||
async function testQueryWithLimit(jayZ?: JayZ) { | ||
const db = await setup(jayZ) | ||
const [musician, song1, song2] = aMusicianWithTwoSongs() | ||
await Promise.all([db.put(musician), db.put(song1), db.put(song2)]) | ||
const result = await db | ||
.query(MusicianPartition.key({ id: musician.id })) | ||
.maxRecordsToProcess(1) | ||
.exec() | ||
expect(result).toEqual({ musician: [musician] }) | ||
} | ||
async function testQueryWithReverseAndLimit(jayZ?: JayZ) { | ||
const db = await setup(jayZ) | ||
const [_, song1, song2] = aMusicianWithTwoSongs() | ||
await Promise.all([db.put(song1), db.put(song2)]) | ||
const result = await db | ||
.query(MusicianPartition.key({ id: song1.musicianId })) | ||
.maxRecordsToProcess(1) | ||
.reverse() | ||
.exec() | ||
expect(result).toEqual({ song: [song2] }) | ||
} | ||
async function testBatchGet(jayZ?: JayZ) { | ||
@@ -178,0 +223,0 @@ const db = await setup(jayZ) |
Sorry, the diff of this file is not supported yet
156419
3002