select promise never resolves

So basically I don't know what is going wrong, because I've been following the documentation as well as a youtube tutorial, and it worked for them, but when I try to select data from my database the app just hangs and does nothing. This is my client setup:
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
import pg from "pg";

import Program from "../../program";
import databaseConfiguration from "../../../database_configuration";
import * as schema from "./schema";
export default class Postgres {
public program: Program
public connection: NodePgDatabase<typeof schema>;

private client: pg.Client;

constructor(program: Program) {
this.program = program;
this.program.utils.log("info", "Connecting to PostgreSQL database...");
console.log(databaseConfiguration);
if (databaseConfiguration.url) {
this.program.utils.log("info", "Using URL connection string");
this.client = new pg.Client({ connectionString: databaseConfiguration.url });
} else {
this.program.utils.log("info", "Using manual connection configuration");
this.client = new pg.Client({
database: databaseConfiguration.database,
host: databaseConfiguration.host,
port: databaseConfiguration.port,
user: databaseConfiguration.user,
password: databaseConfiguration.password,
ssl: databaseConfiguration.ssl
});
}

this.connection = drizzle(this.client, {
schema
});
}
}
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
import pg from "pg";

import Program from "../../program";
import databaseConfiguration from "../../../database_configuration";
import * as schema from "./schema";
export default class Postgres {
public program: Program
public connection: NodePgDatabase<typeof schema>;

private client: pg.Client;

constructor(program: Program) {
this.program = program;
this.program.utils.log("info", "Connecting to PostgreSQL database...");
console.log(databaseConfiguration);
if (databaseConfiguration.url) {
this.program.utils.log("info", "Using URL connection string");
this.client = new pg.Client({ connectionString: databaseConfiguration.url });
} else {
this.program.utils.log("info", "Using manual connection configuration");
this.client = new pg.Client({
database: databaseConfiguration.database,
host: databaseConfiguration.host,
port: databaseConfiguration.port,
user: databaseConfiguration.user,
password: databaseConfiguration.password,
ssl: databaseConfiguration.ssl
});
}

this.connection = drizzle(this.client, {
schema
});
}
}
And I'm trying to select from a table I have in my database
export const Users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").unique().notNull(),
passwordDigest: text("password_digest").notNull(),
salt: text("salt").notNull(),
createdAt: date("created_at").notNull().defaultNow(),
updatedAt: date("updated_at").notNull().defaultNow()
});
export const Users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").unique().notNull(),
passwordDigest: text("password_digest").notNull(),
salt: text("salt").notNull(),
createdAt: date("created_at").notNull().defaultNow(),
updatedAt: date("updated_at").notNull().defaultNow()
});
Using this code
this.router.get("/test", async (req, res) => {
this.program.utils.log("info", "Test endpoint hit");
const users = await this.program.database.connection.select().from(Users);
this.program.utils.log("info", "Users fetched from database");
res.status(200).json(users);
this.program.utils.log("info", "Users sent to client");
});
this.router.get("/test", async (req, res) => {
this.program.utils.log("info", "Test endpoint hit");
const users = await this.program.database.connection.select().from(Users);
this.program.utils.log("info", "Users fetched from database");
res.status(200).json(users);
this.program.utils.log("info", "Users sent to client");
});
But once I go to the test page, it just starts loading forever and all I see in the logs is the image I attached. The weirdest part is that I set up my drizzle config to use the same databaseConfiguration constant and using drizzle studio I can interact with the database fine
No description
2 Replies
Menel
MenelOP7mo ago
No description
No description
Menel
MenelOP7mo ago
Ok I realized I forgot to call client.connect...
Want results from more Discord servers?
Add your server