yiisoft / yiisoft/data-db

Add SQL expression to Sort config

Open
#129 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:enhancement
Dominant language
PHP
Stars
14
Forks
3
Avg merge
1h 6m
Merged PRs (30d)
1

Description

Proposed new feature or change

Add the ability to provide array|string|ExpressionInterface as the sort direction, which will be used as a parameter for Query::orderBy().

'name' => [
    'asc' => new Expression("(substring(name, '^[0-9]+'))::int ASC, lower(name) ASC, LENGTH(name) ASC, split_part(name, '/', 2) ASC"),
    'desc' => new Expression("(substring(name, '^[0-9]+'))::int DESC, lower(name) DESC, LENGTH(name) DESC, split_part(name, '/', 2) DESC"),
],

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 by locating the Sort configuration and the call to Query::orderBy(), then inspect how ascending and descending values are currently handled. The change is done when array, string, and ExpressionInterface sort values can be passed through for both directions and the existing database sorting behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.