Skip to content

Commit

Permalink
Defect/indexeswithoutsksincorrectindexes (#20)
Browse files Browse the repository at this point in the history
* adding patch and create methods. both automatically add ConditionExpressions to either make sure the record exists before updating (patch) or make sure the record doesnt already exist (create)

* adding tests, not full working right now

* query had a defect preventing queries from being ran on tables without an sk. yikes.

* bumping version

* readme improvements

* when the primary pk and sk were part of a collection, scan did not correctly add the collection name to the key structure

* removing debug file and console log from test

* indexes without SKs would not have properly formatted keys. Before this commit, electro relied on the SK as the only means to segregate entities. With this change, if only an PK is present, the entity name will be place in the PK
  • Loading branch information
tywalch committed Jul 26, 2020
1 parent d93d6e5 commit 2610ea2
Show file tree
Hide file tree
Showing 2 changed files with 421 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ class Entity {
}

/* istanbul ignore next */
_getPrefixes({ collection = "", customFacets = {} } = {}) {
_getPrefixes({ collection = "", customFacets = {}, sk } = {}) {
/*
Collections will prefix the sort key so they can be queried with
a "begins_with" operator when crossing entities. It is also possible
Expand Down Expand Up @@ -933,6 +933,10 @@ class Entity {
keys.sk.prefix = this.model.prefixes.sk;
}

if (sk === undefined) {
keys.pk.prefix += keys.sk.prefix;
}

if (customFacets.pk) {
keys.pk.prefix = "";
keys.pk.isCustom = customFacets.pk;
Expand All @@ -954,6 +958,7 @@ class Entity {
}
let facets = this.model.facets.byIndex[index];
let prefixes = this._getPrefixes(facets);
// let sk = [];
let pk = this._makeKey(
prefixes.pk.prefix,
facets.pk,
Expand Down Expand Up @@ -1121,6 +1126,9 @@ class Entity {
seenIndexes[indexName] = indexName;
let hasSk = !!index.sk;
let inCollection = !!index.collection;
if (!hasSk && inCollection) {
throw new Error(`Invalid index definition: Access pattern, ${accessPattern} ${indexName || "(PRIMARY INDEX)"}, contains a collection definition without a defined SK. Collections can only be defined on indexes with a defined SK.`);
}
let collection = index.collection || "";
let customFacets = {
pk: false,
Expand Down

0 comments on commit 2610ea2

Please sign in to comment.