loopbackio / loopbackio/loopback-next

Enabling typecast for model properties in filter object of query

Open
#6,971 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature major Repository
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

Suggestion

I would like to see a option to typecast the model fields in filter object of find query, i.e in short I would like to run sql query equivalent to

Select * from feature where CAST(createdDate as date) > getdate()-4 order by createdDate

here type of createdDate field is string in database

Use Cases

This would be useful to execute queries by changing the type in runtime without modifying the database tables types.
Currently we can bypass this by running repository.execute() command but return type of this query is 'AnyObject' which not useful.

Examples

repository.find({castTo:['createdDate date'],order:['createdDate ASC'],where:{createdDate:{gt:addDays(new Date(),-4).toString()}}})
here castTo property can be used to typecast any filed to desired type

Acceptance criteria

TBD - will be filled by the team.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the repository.find filter path and compare it with repository.execute, the entry points mentioned in the issue. Clarify the missing acceptance criteria with maintainers, including supported cast expressions and the expected result type; done requires an agreed design and tests for runtime field casting.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
backend-api-design, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.