After creating an object with database-related methods, I encountered a problem where the connection to the database was lost because the create method wasn't being called. Can someone shed light on this issue?
Before (It works):
export const connection = createConnection();
Index file:
import { connection } from "./utils/database";
async () => {
try {
await connection;
} catch (error) {
console.error(error);
}
};
After:
export const connection = {
async create() {
console.log("not showing in console");
await createConnection();
},
async close() {
await getConnection().close();
},
};
Index file:
import { connection } from "./utils/database";
async () => {
try {
await connection.create();
} catch (error) {
console.error(error);
}
};