Search code examples
restfeathersjs

Feathersjs REST Query $like


I have an problem to send a REST query to featherjs with the $like operator.

Table:

ID Textfield

1 andreas

Query get

localhost:3030/table?textfield[$like]=andreas

returs the row

Query get localhost:3030/table?textfield[$like]=andrea

localhost:3030/table?textfield[$like]=andrea%

localhost:3030/table?textfield[$like]=andrea*

all this query return 0 rows

Model is Sequelize -> SQL Server

Whats wrong with the url.


Solution

  • I setup your example with the addition of a createdAt and updatedAt field in your test table.

    I used a feathersjs Model of Sequelize -> MySQL

    Table:

    ID Textfield

    1 andreas

    I used postman to test your GET queries:

    localhost:3030/table?textfield[$like]=andreas 
    
    returns:
    
    {
      "total": 1,
      "limit": 20,
      "skip": 0,
      "data": [
        {
         "id": 1,
          "textfield": "andreas",
          "createdAt": "2017-06-05T11:33:38.000Z",
          "updatedAt": null
        }
      ]
    }
    
    localhost:3030/table?textfield[$like]=andrea%
    
    returns:
    
    {
      "total": 1,
      "limit": 20,
      "skip": 0,
      "data": [
        {
         "id": 1,
          "textfield": "andreas",
          "createdAt": "2017-06-05T11:33:38.000Z",
          "updatedAt": null
        }
      ]
    }
    
    localhost:3030/table?textfield[$like]=%drea%
    
    returns:
    
    {
      "total": 1,
      "limit": 20,
      "skip": 0,
      "data": [
        {
         "id": 1,
          "textfield": "andreas",
          "createdAt": "2017-06-05T11:33:38.000Z",
          "updatedAt": null
        }
      ]
    }
    

    The following queries should return nothing because 'andrea' can not be exactly matched in the database and the asterisk (*) is not a wild card in the SQL LIKE syntax https://www.w3schools.com/SQL/sql_like.asp :

    localhost:3030/table?textfield[$like]=andrea
    localhost:3030/table?textfield[$like]=andrea*
    
    {
      "total": 0,
      "limit": 20,
      "skip": 0,
      "data": []
    }