20 lines
447 B
JavaScript
20 lines
447 B
JavaScript
import client from "./db-client.js";
|
|
|
|
try {
|
|
await client.connect();
|
|
const result = await client.query("SELECT id, name FROM department ORDER BY name");
|
|
|
|
if (result.rows.length === 0) {
|
|
console.log("No departments found.");
|
|
}
|
|
|
|
result.rows.forEach((departmentRow) => {
|
|
console.log(`${departmentRow.id}: ${departmentRow.name}`);
|
|
});
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
} finally {
|
|
await client.end();
|
|
}
|