Open Odas0R opened 1 year ago
Just figured out that if I cast it to json, there's a JSON.parse being done? Confused, maybe this might not be a bug.
// This works
extras: {
polygon: sql`ST_AsGeoJSON(${polygon.geometry})::json`
.mapWith(polygon.geometry)
.as("polygon"),
centroid: sql`ST_AsGeoJSON(${polygon.centroid})::json`
.mapWith(polygon.centroid)
.as("centroid"),
}
Still the fromDriver
is not being executed on the example above? I'm a bit confused.
I'm noticing that decoders on sql statements that are part of subqueries aren't being executed - I'm wondering if that's related?
I think I have the same issue. For example, a program
table that has many(student)
:
const res = await db.query.program.findMany({
extras: {
studentsCount: sql<number>`(select count(*) from student s where s.program_id = program.id)`
.mapWith(Number)
.as("students_count")
}
});
studentsCount is always returning as a string.
I am experiencing the same, where mapWith
is not doing anything when used with Query API:
const user = await db.query.users.findFirst({
extras: (user, { sql }) => ({
displayCorrections: sql<boolean>`COALESCE(JSON_VALUE(${user.settings}, '$.displayCorrections'), 0)`
.mapWith({ mapFromDriverValue: (value) => value === 1 })
.as('displayCorrections'),
dashboardLayout: sql<object>`JSON_VALUE(${user.settings}, '$.dashboardLayout')`.as('dashboardLayout'),
}),
where: (user, { eq }) => eq(user.username, username),
})
Also, I couldn't get it to work when the value is NULL, so I had to COALESCE
to default to false.
What version of
drizzle-orm
are you using?0.28.5
What version of
drizzle-kit
are you using?0.19.13
Describe the Bug
The
mapWith
isn't executing thefromDriver
callback on the custom type:Expected behavior
It should parse the value received from the driver, as for now I fix the result with custom hacks.
Environment & setup
NODE: 16.19.1 POP_os: 22.04