Skip to content

Commit

Permalink
Merge 2897277 into c33c77f
Browse files Browse the repository at this point in the history
  • Loading branch information
tywalch committed Nov 23, 2022
2 parents c33c77f + 2897277 commit 608069c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ All notable changes to this project will be documented in this file. Breaking ch
### Fixed
- Addressed issue where scans would incorrectly accumulate filters across usages

## [2.2.6] - 2022-11-22
## [2.3.0] - 2022-11-22
### Added
- Adding new update method: `upsert`. Upsert is similar to `put` in that it will create a record if one does not exist, except `upsert` perform an update if that record already exists.
- Adding new update method: `upsert`. Upsert is similar to `put` in that it will create a record if one does not exist, except `upsert` perform an update if that record already exists.

## [2.3.1] - 2022-11-23
### Fixed
- Address issue#179, the query option `table` was not correctly propagated, resulting a failure for that declared the table name was "missing"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrodb",
"version": "2.3.0",
"version": "2.3.1",
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ class Entity {

if (validations.isStringHasLength(option.table)) {
config.params.TableName = option.table;
config.table = option.table;
}

if (option.concurrent !== undefined) {
Expand Down
117 changes: 116 additions & 1 deletion test/ts_connected.crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4294,4 +4294,119 @@ describe('upsert', () => {
}).params();
}).to.throw('Incomplete composite attributes: Without the composite attributes "createdAt" the following access patterns cannot be updated: "projects" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes')
});
});
});

describe('batch operations', () => {
it('should return batchGet records when "table" is provided as query option', async () => {
const Segment = new Entity({
model: {
entity: "Segment",
version: "1",
service: "TourContent",
},
attributes: {
tenantId: {
type: "string",
required: true,
},
siteId: {
type: "string",
required: true,
},
segmentId: {
type: "string",
required: true,
// default: () => uuid(),
readOnly: true,
validate: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,
},
name: {
type: "string",
required: true,
},
// createdAt,
// updatedAt,
state: {
type: ["active", "inactive"] as const,
required: true,
},
image: {
type: "map",
required: false,
properties: {
bucket: {
type: "string",
required: false,
},
key: {
type: "string",
required: false,
},
},
},
},
indexes: {
_: {
pk: {
field: 'pk',
composite: ["tenantId", "siteId", "segmentId"],
},
sk: {
field: 'sk',
composite: [],
},
},
site: {
collection: "site",
index: 'gsi1pk-gsi1pk-index',
pk: {
field: 'gsi1pk',
composite: ["tenantId", "siteId"],
},
sk: {
field: 'gis1sk',
composite: ["segmentId"],
},
},
},
}, {client});

type CreateSegment = CreateEntityItem<typeof Segment>;

const items: CreateSegment[] = [];
for (let i = 0; i < 10; i++) {
items.push({
tenantId: uuid(),
siteId: uuid(),
name: uuid(),
image: {
bucket: uuid(),
key: uuid(),
},
segmentId: uuid(),
state: 'active'
});
}

await Segment.put(items).go({table});

const first = await Segment.get({
segmentId: items[0].segmentId!,
siteId: items[0].siteId!,
tenantId: items[0].tenantId!
}).go({table});

expect(first.data).to.deep.equal(items[0]);

const batchGet = await Segment.get(items).go({table});
expect(batchGet.data).to.have.length.greaterThan(0);
expect(batchGet.data).to.have.length(items.length);
expect(
batchGet.data
.sort((a, z) => a.segmentId.localeCompare(z.segmentId))
).to.deep.equal(
items
.sort((a, z) => a.segmentId.localeCompare(z.segmentId))
);
});
})

0 comments on commit 608069c

Please sign in to comment.