Skip to content

Commit 840b1ec

Browse files
authored
Fix missing ProjectionExpression on scan with attributes (#511)
* fix: missing ProjectionExpression on scan with attributes * add tests * add changelog * 3.4.5
1 parent 39bcffc commit 840b1ec

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,8 @@ All notable changes to this project will be documented in this file. Breaking ch
590590
- [Issue #439](https://github.com/tywalch/electrodb/issues/439); Fixed missing TypeScript types for `attributes` property on `scan`, `find`, and `match` methods.
591591

592592
## [3.4.4]
593-
- Reduced ElectroDB's pre/post-processing overhead before/after DynamoDB requests by as much as 85% in some cases.
593+
- Reduced ElectroDB's pre/post-processing overhead before/after DynamoDB requests by as much as 85% in some cases.
594+
595+
## [3.4.5]
596+
### Fixed
597+
- [Issue #510](https://github.com/tywalch/electrodb/issues/510); Fixes the issue where ElectroDB did not create the ProjectionExpression DynamoDB parameter when scanning a table and specifying attributes to return.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electrodb",
3-
"version": "3.4.4",
3+
"version": "3.4.5",
44
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
55
"main": "index.js",
66
"scripts": {

src/entity.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,10 @@ class Entity {
20122012
);
20132013
break;
20142014
case MethodTypes.scan:
2015-
params = this._makeScanParam(filter[ExpressionTypes.FilterExpression]);
2015+
params = this._makeScanParam(
2016+
filter[ExpressionTypes.FilterExpression],
2017+
config,
2018+
);
20162019
break;
20172020
/* istanbul ignore next */
20182021
default:
@@ -2228,7 +2231,7 @@ class Entity {
22282231
}
22292232

22302233
/* istanbul ignore next */
2231-
_makeScanParam(filter = {}) {
2234+
_makeScanParam(filter = {}, options = {}) {
22322235
let indexBase = TableIndex;
22332236
let hasSortKey = this.model.lookup.indexHasSortKeys[indexBase];
22342237
let accessPattern =
@@ -2291,7 +2294,10 @@ class Entity {
22912294
params.FilterExpression = filterExpressions.join(" AND ");
22922295
}
22932296

2294-
return params;
2297+
return this._applyProjectionExpressions({
2298+
parameters: params,
2299+
config: options,
2300+
});
22952301
}
22962302

22972303
_makeSimpleIndexParams(partition, sort) {

test/ts_connected.crud.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,6 +4380,16 @@ describe("attributes query option", () => {
43804380
},
43814381
]);
43824382

4383+
4384+
const scanParams = entityWithSK.scan.params({
4385+
// @ts-ignore - the ParamOptions type does not accept attributes
4386+
// but this is valid in runtime
4387+
attributes: ["attr2", "attr9", "attr5", "attr10"],
4388+
});
4389+
expect(scanParams.ProjectionExpression).to.equal(
4390+
"#__edb_e__, #__edb_v__, #pk, #sk, #attr2, #prop9, #attr5, #attr10",
4391+
);
4392+
43834393
const matchItem = await entityWithSK
43844394
.match({
43854395
attr1: item.attr1,

0 commit comments

Comments
 (0)