Ꚃimon
Ꚃimon
Explore posts from servers
DTDrizzle Team
Created by Ꚃimon on 6/6/2024 in #help
colBuilder.buildExtraConfigColumn is not a function
I get the above error when running drizzle-kit studio.
"drizzle-orm": "^0.31.1",
"@neondatabase/serverless": "^0.9.3",
"drizzle-kit": "^0.22.2",
"drizzle-orm": "^0.31.1",
"@neondatabase/serverless": "^0.9.3",
"drizzle-kit": "^0.22.2",
1 replies
DTDrizzle Team
Created by Ꚃimon on 8/9/2023 in #help
Nullable relational query?
In the following, shouldn't res.jobSeekerProfile possibly be null? Basically what I want is to get the user - Include their jobSeekerProfile (if they have one). Currently, it seems to assume that jobSeekerProfile always exists for the user
let test = db.query.users.findFirst({
where: (users, { eq }) => eq(users.id, '1'),
with: {
jobSeekerProfile: true,
},
})

test.then((res) => {
if (res) {
res.jobSeekerProfile
}
})
let test = db.query.users.findFirst({
where: (users, { eq }) => eq(users.id, '1'),
with: {
jobSeekerProfile: true,
},
})

test.then((res) => {
if (res) {
res.jobSeekerProfile
}
})
It's telling me it's this type:
res: {
id: string;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
createdAt: Date;
updatedAt: Date;
jobSeekerProfile: {
id: string;
userId: string;
bio: string | null;
cvUrl: string | null;
};
}
res: {
id: string;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
createdAt: Date;
updatedAt: Date;
jobSeekerProfile: {
id: string;
userId: string;
bio: string | null;
cvUrl: string | null;
};
}
Shouldn't jobSeekerProfile be nullable? This is the schema:
export const users = pgTable('users', {
id: text('id').notNull().primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
image: text('image'),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull(),
})

export const userRelations = relations(users, ({ one }) => ({
jobSeekerProfile: one(jobSeekerProfiles, {
fields: [users.id],
references: [jobSeekerProfiles.userId],
}),
}))

export const jobSeekerProfiles = pgTable('jobSeekerProfiles', {
id: text('id').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
bio: text('bio'),
cvUrl: text('cvUrl'),
})
export const users = pgTable('users', {
id: text('id').notNull().primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
image: text('image'),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull(),
})

export const userRelations = relations(users, ({ one }) => ({
jobSeekerProfile: one(jobSeekerProfiles, {
fields: [users.id],
references: [jobSeekerProfiles.userId],
}),
}))

export const jobSeekerProfiles = pgTable('jobSeekerProfiles', {
id: text('id').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
bio: text('bio'),
cvUrl: text('cvUrl'),
})
15 replies