bigint is not a number

I'm trying to execute this query but get the following error that I'm hoping someone here can help me with:
const profilePhoto = await ctx.db.query.profile.findFirst({
where: eq(schema.profile.id, profile.profileId),
columns: {
profilePhotoId: true,
},
})
const profilePhoto = await ctx.db.query.profile.findFirst({
where: eq(schema.profile.id, profile.profileId),
columns: {
profilePhotoId: true,
},
})
but get the following overload error:
Argument of type bigint is not assignable to parameter of type number | SQLWrapper.
Argument of type bigint is not assignable to parameter of type number | SQLWrapper.
My schema for the related fields are also posted below.
export const profile = mySqlTable("Profile", {
id: serial("id").primaryKey(),
userName: varchar("userName", { length: 255 }).unique().notNull(),
bio: text("bio"),
profilePhotoId: bigint("profilePhoto", {mode: "bigint", unsigned: true}).references(() => profilePhoto.id),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const profileRelations = relations(profile, ({ one, many }) => ({
profilePhoto: one(profilePhoto, {
fields: [profile.profilePhotoId],
references: [profilePhoto.id],
}),
posts: many(post),
}));

export const profilePhoto = mySqlTable("ProfilePhoto", {
id: serial("id").primaryKey().notNull(),
url: varchar("url", { length: 255 }).notNull(),
// key: varchar("varchar", { length: 255 }).notNull(),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const profilePhotoRelations = relations(profilePhoto, ({ one }) => ({
profile: one(profile, {
fields: [profilePhoto.id],
references: [profile.id],
}),
}));
export const profile = mySqlTable("Profile", {
id: serial("id").primaryKey(),
userName: varchar("userName", { length: 255 }).unique().notNull(),
bio: text("bio"),
profilePhotoId: bigint("profilePhoto", {mode: "bigint", unsigned: true}).references(() => profilePhoto.id),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const profileRelations = relations(profile, ({ one, many }) => ({
profilePhoto: one(profilePhoto, {
fields: [profile.profilePhotoId],
references: [profilePhoto.id],
}),
posts: many(post),
}));

export const profilePhoto = mySqlTable("ProfilePhoto", {
id: serial("id").primaryKey().notNull(),
url: varchar("url", { length: 255 }).notNull(),
// key: varchar("varchar", { length: 255 }).notNull(),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const profilePhotoRelations = relations(profilePhoto, ({ one }) => ({
profile: one(profile, {
fields: [profilePhoto.id],
references: [profile.id],
}),
}));
6 Replies
Mykhailo
Mykhailo10mo ago
Hello, @'tonyyprints'! Could you please clarify what is the value of profile.profileId?
'tonyyprints'
'tonyyprints'OP10mo ago
This is where profile comes from. profileId should be the serial index of the row
const profile = await ctx.db.query.user.findFirst({

where: eq(schema.user.id, input.metadata.id),
columns: {
profileId: true,
},
});
if (!profile?.profileId) {
// For now, assume a profile is always created in the auth flow
throw new TRPCError({message: "User profile not found", code: "NOT_FOUND"});
}
const profile = await ctx.db.query.user.findFirst({

where: eq(schema.user.id, input.metadata.id),
columns: {
profileId: true,
},
});
if (!profile?.profileId) {
// For now, assume a profile is always created in the auth flow
throw new TRPCError({message: "User profile not found", code: "NOT_FOUND"});
}
Mykhailo
Mykhailo10mo ago
could you please show me your user schema?
'tonyyprints'
'tonyyprints'OP10mo ago
happy to:
export const user = mySqlTable("User", {
id: varchar("id", {length: 255}).primaryKey(),
// email: varchar("email", { length: 255 }).unique().notNull(),
name: varchar("name", { length: 255 }),
dateOfBirth: date("dateOfBirth"),
profileId: bigint("profileId", {mode: "bigint", unsigned: true}).references(() => profile.id),
notificationSetting: bigint("notificationSetting", {mode: "bigint", unsigned: true}).references(
() => notificationSetting.id,
),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const userRelations = relations(user, ({ one }) => ({
profile: one(profile, {
fields: [user.profileId],
references: [profile.id],
}),
notificationSetting: one(notificationSetting, {
fields: [user.notificationSetting],
references: [notificationSetting.id],
}),
}));
export const user = mySqlTable("User", {
id: varchar("id", {length: 255}).primaryKey(),
// email: varchar("email", { length: 255 }).unique().notNull(),
name: varchar("name", { length: 255 }),
dateOfBirth: date("dateOfBirth"),
profileId: bigint("profileId", {mode: "bigint", unsigned: true}).references(() => profile.id),
notificationSetting: bigint("notificationSetting", {mode: "bigint", unsigned: true}).references(
() => notificationSetting.id,
),
createdAt: timestamp("createdAt")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
});

export const userRelations = relations(user, ({ one }) => ({
profile: one(profile, {
fields: [user.profileId],
references: [profile.id],
}),
notificationSetting: one(notificationSetting, {
fields: [user.notificationSetting],
references: [notificationSetting.id],
}),
}));
Mykhailo
Mykhailo10mo ago
okay, so the issue is with mode: bigint. In your application, mode is used to infer the type, which means that profileId is treated as having a bigint type in JavaScript/TypeScript. However, schema.profile.id is treated as having a number type in JavaScript/TypeScript. This is why you're encountering an error. Can you update your schema code and set mode: number?
'tonyyprints'
'tonyyprints'OP10mo ago
ohhhhh that makes so much sense. Thank you. Just replaced all instances to number and it works 🙏
Want results from more Discord servers?
Add your server