0

I need dynamoose query equivalent to this SQL query select * from employees where first_name like '%fish%' or last_name like '%fish%'.

I tried below code but doesn't work.

 const employees = EmsModel.query('pk')
    .eq('emp_prof')
    .and()
    .where('first_name')
    .contains(params.name)
    .or()
    .where('last_name')
    .contains(params.name)
    .exec();

can anyone guide me.

Udhaya
  • 121
  • 1
  • 14

1 Answers1

0

this works for me!

const employees = EmsModel.query('pk')
    .eq('emp_prof')
    .and()
    .parenthesis(new dynamoose.Condition().where('first_name').contains(param).or().where('last_name').contains(param))
    .exec();
payloc91
  • 3,724
  • 1
  • 17
  • 45
Udhaya
  • 121
  • 1
  • 14
  • but now I need to fix case sensitive. it doesn't work if my param value is 'fish' and actual value stored in DB is 'Fish' – Udhaya Oct 30 '20 at 12:21
  • 2
    This is a different question. The answer is that DynamoDB does not currently give you any way to do case-insensitive comparison. The best option you have is for your application to write in addition to the first_name column also a first_name_lowercase column with the lowercase version of the name. Then, you can do comparisons on this first_name_lowercase field. – Nadav Har'El Oct 30 '20 at 16:08
  • Yes, this one helps. https://stackoverflow.com/questions/44284045/query-dynamodb-with-case-insensitive-condition – Udhaya Oct 31 '20 at 07:52