How to concat two columns for search with feathers-sequelize?

1.3k views Asked by At

I need to search for users by name, their first name and last names are stored in separate columns in a postgresql database. The columns need to be concatenated for search to work properly. Typing the full first and last name of a user should match a result.

What could I pass as a query to the find method of a Feathers service that would allow me to do this?

1

There are 1 answers

0
Daff On

As in the answer linked you can pass the where clause to the Feathers service by modifying params.query in a before hook:

app.service('users').before({
  find(hook) {
    const where = Sequelize.where(Sequelize.fn("concat",
      Sequelize.col("firstname"),
      Sequelize.col("lastname")), {
        like: '%John Do%'
      }
    );

    hook.params.query.where = where;
  }
})