GetDutchie / brick

An intuitive way to work with persistent data in Dart

Home Page:https://getdutchie.github.io/brick/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to convert a model field to a small letter in a Query?

Dan-Crane opened this issue · comments

commented

Hi, thanks for good library.

i want to get data from SQLite case insensitive
for example:

get<Pizza>(
  query: Query(
    where: [
      const And('LOWER(description)').contains(searchQuery),
    ],
  ),
  hydrateUnexisting: false,
)

How i can do it?

@dimiskil You can't make SQL calls directly with Brick unless you use sqliteProvider.rawQuery or sqliteProvider.rawExecute, both of which I would recommend not using as you'll become excluded from future Brick APIs and optimizations. Instead, for this case, I would use a computed getter.

class Pizza {
  @Rest(ignore: true)
  String get lowerCaseDescription => description.toLowerCase();
}

// Where('lowerCaseDescription').contains(searchQuery)

But in these instances I find it's better to modify the search query instead:

Query(
  where: [
    Where('description').contains(searchQuery.toLowerCase()),
    Or('description').contains(searchQuery),
  ],
)
commented

thanks!)