Improve `QueryInterface::withTypecasting()` method
Open
Nobody has claimed this yet.
severity:BC breaking
type:enhancement
- Dominant language
- PHP
- Stars
- 216
- Forks
- 51
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 2
Description
Proposed new feature or change
- to avoid additional database queries to obtain column information for type casting;
- to be able to specify a custom type for columns for type casting.
A possible solution is to add ability to specify types for casting directly for each column in query results:
$query->withTypecasting([
'*' => true, // automatically typecast all columns using `PDOStatement::getColumnMeta()`
'name' => ColumnType::STRING, // abstract type
'age' => 'int', // database type
'birthday' => false, // do not typecast
'is_active' => new BooleanColumn(),
'created_at' => new DateTimeColumn(),
]);
The types can be presented as
- instances of
ColumnInterface; - string names of types (e.g.
int,char(20),json, etc); trueto automatically detect type usingPDOStatement::getColumnMeta();- empty value (
null,falseor '') which means without typecasting.
Also possible to use * as a column name to specify default type for all columns.
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 by locating QueryInterface::withTypecasting() and the existing type-casting flow. Review how column metadata and type definitions are currently obtained, then identify tests covering casting behavior. Done should support per-column and wildcard type specifications, automatic metadata detection, and explicitly disabled casting without unnecessary database queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100