Skip to content

Commit

Permalink
DEV: add Table.scanModels
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Brien committed Feb 6, 2021
1 parent 837f414 commit 686dc08
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Table {
} = params

this.logger = logger
this.log('trace', `Loading DDB`, {params})
this.log('trace', `Loading OneTable`, {params})

this.params = params
this.client = client
Expand Down Expand Up @@ -243,6 +243,21 @@ export default class Table {
return await this.generic.updateItem(properties, params)
}

async scanModels(models, params) {
let where = []
for (let model of models) {
where.push('(${' + this.typeField + '} == {' + model + '})')
}
where = where.join(' or ')
params = Object.assign({where, parse: true, hidden: false}, params)
let items = await this.generic.scanItems({}, params)
let result = {}
for (let item of items) {
result[item[this.typeField]] = item
}
return result
}

/*
Invoke a prepared transaction
*/
Expand Down

0 comments on commit 686dc08

Please sign in to comment.