As it is known dynamodb have a serious black list of reserve key words that we often forgot when building our tables. However when the time comes to update or query your data you run into this weird snytax that we constanty have to research.
This lirary is here to take that headache away by writing the queries for you with just a few steps.
Install:
$ npm i @knymbus/dynano-query-builder
import { DynamoQueryBuilder, FilterOption } from "@knymbus/dynamo-query-builder"
const TABLENAME = "My-dynamo-table-name"
export const queryItems = async ()=>{
const queryBuilder = new DynamoQueryBuilder()
queryBuider
.setTableName(tableName)
..setQuery({
filter: {
fields: [
{
field: "Ast",
comparison: FilterOption.eq,
value: "some_status_id",
join: 'nd'
},
{
field: 'block',
comparison: FilterOption.eq,
value: "A",
join: "/"
},
{
field: "block",
comparison: FilterOption.eq,
value: "B",
join: null
}
],
key: {
field: "accId",
comparison: FilterOption.eq,
value: "partition-accId"
}
}
})
// async/await option
const result = await queryBuider.execute()
// or the promise way
queryBuider.execute().then(result=>{
console.log(result)
}).catch(err=>{
console.log(err)
})
}