King of the Short Bus
King of the Short Bus
DTDrizzle Team
Created by King of the Short Bus on 4/3/2024 in #help
findFirst returns array instead of entity - using aws-data-api/pg
Hi folks -- I'm using aws-data-api/pg, running the latest version ("drizzle-orm": "^0.30.7"). I'm seeing something where my query.<table>.findOne() call is correctly typed as <entity>|undefined, and the LIMIT 1 clause is showing up in the SQL, but I'm actually getting back results of the form [<entity>] or [], as I would expect from findMany(). Code:
const dealer = await db.query
.dealer
.findFirst({
columns: {id: true},
where: eq(dealerDef.key, dealerKey)
});
console.debug(`!!!!!!!!!!!!! ${JSON.stringify(dealer)}`)
const dealer = await db.query
.dealer
.findFirst({
columns: {id: true},
where: eq(dealerDef.key, dealerKey)
});
console.debug(`!!!!!!!!!!!!! ${JSON.stringify(dealer)}`)
Log 1 (entity found):
Query: select "id" from "dealer" where "dealer"."key" = :1 limit :2 -- params: [{"name":"1","value":{"stringValue":"valid-key"}}, {"name":"2","value":{"longValue":1}}]
!!!!!!!!!!!!! [{"id":100001}]
Query: select "id" from "dealer" where "dealer"."key" = :1 limit :2 -- params: [{"name":"1","value":{"stringValue":"valid-key"}}, {"name":"2","value":{"longValue":1}}]
!!!!!!!!!!!!! [{"id":100001}]
Log 2 (entity not found):
Query: select "id" from "dealer" where "dealer"."key" = :1 limit :2 -- params: [{"name":"1","value":{"stringValue":"bad-key"}}, {"name":"2","value":{"longValue":1}}]
!!!!!!!!!!!!! []
Query: select "id" from "dealer" where "dealer"."key" = :1 limit :2 -- params: [{"name":"1","value":{"stringValue":"bad-key"}}, {"name":"2","value":{"longValue":1}}]
!!!!!!!!!!!!! []
Changing the code to findMany() changes the type expected by my IDE, but the logs show the same output (same SQL minus the LIMIT 1, and exact same resulting data). Am I doing something wrong here, or should I file a bug?
4 replies