js-data-sql icon indicating copy to clipboard operation
js-data-sql copied to clipboard

LIKEI operator not supported

Open jmdobry opened this issue 9 years ago • 1 comments

Regarding to this documentation LIKEI operator should be supported

http://www.js-data.io/docs/query-syntax

but it is not - at least for DSSqlAdapter (PostgreSQL)

Error is : ERR [Error: Operator not found]

jmdobry avatar Jan 07 '16 01:01 jmdobry

We could use something like WHERE LOWER(name) LIKE LOWER('%foo%') but this will not use indexes

It looks like Postgres has the case insenstive ILIKE but it is not in the SQL standard but is an extension. Also not sure about index use.

MySQL has WHERE name COLLATE UTF8_GENERAL_CI LIKE '%foo%' but not sure if it will still use an index if available or if it's just as bad as the lower option.

Until it's decided how best to handle this, as of version 0.11.10, you can register a custom query operator and provide your own implementation (or override an existing one)

For example, this should work to use ILIKE on postgres (untested though)

var adapter = new DSSqlAdapter({
  client: 'pg',
  queryOperators: {
    'likei': (query, field, value) => query.where(field, 'ilike', value),
    '|likei': (query, field, value) => query.orWhere(field, 'ilike', value)
  }
}

techniq avatar Jan 29 '16 16:01 techniq