How so I execute $query->orderBy('FIELD(node.nid, 5,12,3,6)', 'ASC')? I am currently converting code from Drupal 7 to Drupal 8. So far I am unable to find resources on how to convert the call to orderBy() which uses an expression.

$query-&gt;orderBy("FIELD(node.nid, '5,12,3,6')", 'ASC'); 


Based on D8 Select::orderBy, it only accepts alias or fields.

What is the code I should use in Drupal 8?
I did a workaround by implementing a CASE statement then sorting by the value.

$query-&gt;addExpression("
    CASE node.nid
        WHEN 5 THEN 1
        WHEN 12 THEN 2
        WHEN 3 THEN 3
        WHEN 6 THEN 4
        ELSE 5
    END
", 'order_field');

$query-&gt;orderBy("order_field", 'ASC');


Hopefully they'll add another function to handle these special statements in the future.