loopbackio / loopbackio/loopback-next
Enabling typecast for model properties in filter object of query
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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