Insert or Update: Error undefined is not an object (evaluating 'col.name')

Hi, I'm trying to implement Insert or Update
export async function insertOrUpdateUser(user: UserInsert) {
const db = await getDatabase();

return await db
.insert(users)
.values(user)
.onConflictDoUpdate({
target: users.id,
set: user
});
}
export async function insertOrUpdateUser(user: UserInsert) {
const db = await getDatabase();

return await db
.insert(users)
.values(user)
.onConflictDoUpdate({
target: users.id,
set: user
});
}
I get this error:
TypeError: undefined is not an object (evaluating 'col.name')
at /app/node_modules/drizzle-orm/pg-core/dialect.js:74:41
at buildUpdateSet (/app/node_modules/drizzle-orm/pg-core/dialect.js:72:6)
at onConflictDoUpdate (/app/node_modules/drizzle-orm/pg-core/query-builders/insert.js:57:19)
at /app/src/db/schemas/users.ts:43:15
at processTicksAndRejections (:61:76)
TypeError: undefined is not an object (evaluating 'col.name')
at /app/node_modules/drizzle-orm/pg-core/dialect.js:74:41
at buildUpdateSet (/app/node_modules/drizzle-orm/pg-core/dialect.js:72:6)
at onConflictDoUpdate (/app/node_modules/drizzle-orm/pg-core/query-builders/insert.js:57:19)
at /app/src/db/schemas/users.ts:43:15
at processTicksAndRejections (:61:76)
Any idea what it means ?
15 Replies
Pascal Mattes
Pascal Mattesā€¢13mo ago
Where do you get "users" from?
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
users is my table name
export const users = pgTable('users', {...
export const users = pgTable('users', {...
Pascal Mattes
Pascal Mattesā€¢13mo ago
Okay so you do import users in the file where the function "insertOrUpdateUser" is?
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
Yes, it's in the same exact file There is no TS Error at transpile time, the errors comes from within drizzle's module
Pascal Mattes
Pascal Mattesā€¢13mo ago
Okay. We are doing this the exact same way and for us it is working. Thats why i was asking šŸ™‚
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
mmh If I do that:
return await db
.insert(users)
.values(user)
.onConflictDoUpdate({
target: users.id,
set: {
firstName: user.firstName,
middleName: user.middleName,
lastName: user.lastName,
fullName: user.fullName,
.....
},
});
return await db
.insert(users)
.values(user)
.onConflictDoUpdate({
target: users.id,
set: {
firstName: user.firstName,
middleName: user.middleName,
lastName: user.lastName,
fullName: user.fullName,
.....
},
});
It works, that's puzzling
Pascal Mattes
Pascal Mattesā€¢13mo ago
What version of drizzle-orm are you using?
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
"drizzle-orm": "^0.29.0",
Oh, I think I know why
Pascal Mattes
Pascal Mattesā€¢13mo ago
šŸ™‚ I think there has to be a problem with your user object then
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
My user object has additional properties than columns in the database And I think drizzle doesn't handle that Thanks for your help ā¤ļø
Pascal Mattes
Pascal Mattesā€¢13mo ago
Yes that might be the case. We are using an object which only has the properties drizzle expects
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
I'll stick with this non-elegant solution while i'm working on integrating all user properties
Pascal Mattes
Pascal Mattesā€¢13mo ago
You're welcome šŸ™‚
Cyber Grandma
Cyber GrandmaOPā€¢13mo ago
Have a great rest of your day ;)
Pascal Mattes
Pascal Mattesā€¢13mo ago
You too!
Want results from more Discord servers?
Add your server