How to type prepared statements with typescript

Hi,

I want to use prepared statements with classes in typescript but im unsure on how to type them properly.

Example:

import { schema } from "@db/index.js";
import { sql } from "drizzle-orm";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

export class Test {
    public db: ReturnType<typeof drizzle<typeof schema>>;
    public preparedStatement

    constructor(client: Pool) {
        this.db = drizzle(client, { schema });
        this.preparedStatement = this.db
            .query  
            .guildSettings
            .findFirst({
                where: (fields, { eq }) => eq(fields.guildId, sql.placeholder("id"))
            })
            .prepare("guild_settings")
    }
}

I noticed the NodePgPreparedQuery but im not too sure what the generic is supposed to be.

Thanks
Was this page helpful?