Skip to content

FakeDynamo cannot find local index if there are no conditions #115

@karadaisy

Description

@karadaisy

If I build a query with an index name but without any filter conditons, e.g.

new QueryBuilder()
  .setTableName('Users')
  .setHashKey('userId', ...)
  .setIndexName('isAdmin-index')
  .execute()

FakeDynamo doesn't know which attribute that corresponds to

FakeTable.prototype.query = function(data) {
  var indexedKeyName
  if (data.IndexName) {
    // Global Secondary Index if the index name has three or more
    // parts (separated by '-')
    var indexParts = data.IndexName.split('-')
    var probableGSIIndex = indexParts.length >= 3
    if (probableGSIIndex) {
      return this._queryGlobalSecondaryIndex(data)
    }

    // Extract the range key for Local Secondary Indexes
    for (var key in data.KeyConditions) {
      if (key !== this.primaryKey.hash.name) {
        indexedKeyName = key
      }
    }
  }
  ...

and (silently) fails to find anything as a result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions