After investigating, it seems that the query is always returning rows ordered by id, regardless of the value passed in the sortType variable (verified in console).
export async function fetchAnimalList(sortType) {
noStore();
try {
const areas = await sql<Animals>`
SELECT e.id, e.name, e.slug, e.sliderarray, e.location, e.classification1, a.name AS locationname
FROM animals e
JOIN areas a ON (e.location = a.displayorder)
ORDER BY ${sortType}
`;
return areas.rows;
}
}
The code snippet calling the function with the variable looks like this:
const animalList = await fetchAnimalList('e.name');
When manually replacing ${sortType} with 'e.name', the result is as expected - ordered by e.name. What could be causing this unexpected behavior?