Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 373
Andreas Avatar asked Oct 20 '25 13:10

Andreas


1 Answers

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": []
}
like image 79
user3139574 Avatar answered Oct 22 '25 09:10

user3139574



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!