François
François
Explore posts from servers
PPrisma
Created by François on 4/28/2025 in #help-and-questions
Typed Query parameters not generated
Hey community, I am trying out the typed query feature and run into a problem that might also be faulty usage by me. I got the following raw query file:
-- @param {String} $1:text
-- @param {Int} $2:limit
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_extension
WHERE extname = 'fuzzystrmatch'
) THEN
CREATE EXTENSION fuzzystrmatch SCHEMA matching;
END IF;

SELECT
*, levenshtein(name, $1) AS distance
FROM "matching"."skills"
ORDER BY distance ASC
LIMIT $2;
END
$$;
-- @param {String} $1:text
-- @param {Int} $2:limit
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_extension
WHERE extname = 'fuzzystrmatch'
) THEN
CREATE EXTENSION fuzzystrmatch SCHEMA matching;
END IF;

SELECT
*, levenshtein(name, $1) AS distance
FROM "matching"."skills"
ORDER BY distance ASC
LIMIT $2;
END
$$;
As you can see I defined the parameter manually. I did generate the client and try to call it like this:
return this.database.client.$queryRawTyped(getNearestSkillWithoutType(), name)
return this.database.client.$queryRawTyped(getNearestSkillWithoutType(), name)
TS complains about the name argument provided in the $queryRawTyped call. Providing it int the getNearestSkillWithoutType call also results in a TS error complaining about the extra argument. The documentation is kinda weird too. In the documentation text it says:
When using the generated function in your TypeScript code, pass the arguments as additional arguments to $queryRawTyped
When using the generated function in your TypeScript code, pass the arguments as additional arguments to $queryRawTyped
but the code example provides the arguments in the query call. But my generated client doesnt accept any of those two scenarios. It knows about the query but not about their arguments. Am I missing something?
2 replies
DTDrizzle Team
Created by François on 4/11/2025 in #help
Correct Client type to pass drizzle client around
Hey community, I love drizzle but sometimes I find it quite challenging to deal with the types. I am not sure if this problem is a skill issue, thus I wanna ask you guys. Let me explain: I am using Nest.js and I have DatabaseService file that create the drizzle client internally and exposes it. I want this service to be dynamic which means I want to be able to pass the schema to it and the type of the client should be infered automagically. But I am struggling to properly type it: This is the relevant definitions of my types in the DatabaseService regarding the drizzle client:
type DB<TSchema extends Record<string, unknown>> = PgDatabase<NodePgQueryResultHKT, TSchema> & {
$client: NodePgClient;
};
export declare class DatabaseService<T extends Record<string, unknown>> {
private readonly _client;
client: DB<T>;
get db(): DB<T>;
}
type DB<TSchema extends Record<string, unknown>> = PgDatabase<NodePgQueryResultHKT, TSchema> & {
$client: NodePgClient;
};
export declare class DatabaseService<T extends Record<string, unknown>> {
private readonly _client;
client: DB<T>;
get db(): DB<T>;
}
The underlying schema that I am importing is:
export const offerSkills = pgTable("offer_skills", {
id: uuid().defaultRandom().primaryKey().notNull(),
offerId: uuid().notNull(),
skillId: uuid().notNull(),
mandatory: boolean("mandatory"),
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
})
export const offerSkills = pgTable("offer_skills", {
id: uuid().defaultRandom().primaryKey().notNull(),
offerId: uuid().notNull(),
skillId: uuid().notNull(),
mandatory: boolean("mandatory"),
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
})
3 replies
DTDrizzle Team
Created by François on 10/3/2024 in #help
Anyone also experiencing this issue?
Hey community, I started using drizzle for quering against my PostgreSQL for a project and noticed a HUUUUUGE query time that I did not expect. My observations can be found here: https://github.com/drizzle-team/drizzle-orm/issues/3001 Do you guys experience the same weird behavior with different versions of the pg module?
8 replies