const query = `
SELECT
id,
updated_at
FROM mail_providers
ORDER BY $1 $2
`;
this.pg.query(query, ['updated_at', 'DESC']);
const { Pool } = require('pg');
const pool = new Pool();
const allowedSortDirections = ['ASC', 'DESC'];
async function sortByField(field, direction) {
if (!allowedSortDirections.includes(direction)) {
throw new Error(`Недопустимое направление сортировки: ${direction}. Допустимыми значениями являются: ${allowedSortDirections.join(', ')}`);
}
const result = await pool.query(`SELECT id, updated_at FROM mail_providers ORDER BY $1 ${direction}`, [field]);
return result.rows;
}
sortByField('updated_at', 'DESC')