Jelly Fin: Should I use a query or scan?

offendingcommit

Jonathan Irvin

Posted on August 28, 2018

Jelly Fin: Should I use a query or scan?

Hey Dev.to,

I have an endpoint where I'm trying to get a subset of transactions by date using between. When I run this, I get no results. Odd thing is, I get no errors either.

I know, I know...why not post this on StackOverflow. I don't feel like being judged and you guys are much more supportive. :)

// get transactions for {month} and {year}
api.get('/transaction/tab/{year}/{month}', (request) => {
  const year = request.pathParams.year
  const month = request.pathParams.month
  const params = {
    TableName: request.env.tableName,
    KeyConditionExpression: '#date between :val1 and :val2',
    ExpressionAttributeNames: {
      '#date': 'date'
    },
    ExpressionAttributeValues: {
      ':d': 'date',
      ':val1': year +'-'+month+'-01',
      ':val2': year +'-'+month+'-'+getDaysInMonth(month, year)
    }
  }

  console.log(params)

  // post-process dynamo result before returning
  dynamoDb.query(params, (err, data) => {
    console.log(data)
    if (err) {
      console.error('Unable to query. Error:', JSON.stringify(err, null, 2))
      return 'Unable to query. Error: '+ JSON.stringify(err, null, 2)
    } else {
      console.log('Query succeeded.')
      data.Items.forEach((item) => {
        console.log(' -', item.year + ': ' + item.title)
      })
      return data.Items
    }
  })
})
Enter fullscreen mode Exit fullscreen mode

Here's my data model:

{
    id: String
    date: String
    ...
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
offendingcommit
Jonathan Irvin

Posted on August 28, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related