carlos
carlos
Explore posts from servers
DTDrizzle Team
Created by carlos on 8/11/2023 in #help
There is not enough information to infer relation
export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));

export const filesRelations = relations(historyFiles, ({ one }) => ({
history: one(histories, {
fields: [historyFiles.historyId],
references: [histories.id],
}),
}));
export const historyRelations = relations(histories, ({ many }) => ({
files: many(historyFiles),
}));

export const filesRelations = relations(historyFiles, ({ one }) => ({
history: one(histories, {
fields: [historyFiles.historyId],
references: [histories.id],
}),
}));
5 replies
DTDrizzle Team
Created by carlos on 8/11/2023 in #help
There is not enough information to infer relation
was missing the relation on the other side
5 replies
DTDrizzle Team
Created by carlos on 8/11/2023 in #help
There is not enough information to infer relation
got it
5 replies
DTDrizzle Team
Created by carlos on 5/12/2023 in #help
schema generates wrong index
"drizzle-orm": "^0.23.13",
"drizzle-kit": "^0.17.4",
"drizzle-orm": "^0.23.13",
"drizzle-kit": "^0.17.4",
5 replies
DTDrizzle Team
Created by carlos on 5/12/2023 in #help
schema generates wrong index
export const histories = pgTable('histories', {
id: serial('id').primaryKey(),
medicalHistoryNumber: text('medical_history_number').notNull(),
doctor: text('doctor').notNull(),
division: text('division').notNull(),
comments: text('comments').notNull(),
date: timestamp('date').notNull(),
type: historyTypeEnum('type').notNull(),
state: historyStateEnum('state').notNull(),
creatorId: integer('creator_id')
.references(() => users.id)
.notNull(),

hospitalId: integer('hospital_id')
.references(() => organizations.id)
.notNull(),
providerId: integer('provider_id')
.references(() => organizations.id)
.notNull(),

createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),

createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export const files = pgTable('files', {
id: serial('id').primaryKey(),
filename: text('filename').notNull(),
key: text('key').notNull(),
uploadedBy: integer('uploaded_by')
.references(() => users.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const histories = pgTable('histories', {
id: serial('id').primaryKey(),
medicalHistoryNumber: text('medical_history_number').notNull(),
doctor: text('doctor').notNull(),
division: text('division').notNull(),
comments: text('comments').notNull(),
date: timestamp('date').notNull(),
type: historyTypeEnum('type').notNull(),
state: historyStateEnum('state').notNull(),
creatorId: integer('creator_id')
.references(() => users.id)
.notNull(),

hospitalId: integer('hospital_id')
.references(() => organizations.id)
.notNull(),
providerId: integer('provider_id')
.references(() => organizations.id)
.notNull(),

createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),

createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export const files = pgTable('files', {
id: serial('id').primaryKey(),
filename: text('filename').notNull(),
key: text('key').notNull(),
uploadedBy: integer('uploaded_by')
.references(() => users.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
5 replies
DTDrizzle Team
Created by carlos on 5/1/2023 in #help
inArray
const [selectHistories, countHistories] = await Promise.all([
state.length ? await db.with(main).select().from(main).where(inArray(histories.state, state)) : await db.with(main).select().from(main),
const [selectHistories, countHistories] = await Promise.all([
state.length ? await db.with(main).select().from(main).where(inArray(histories.state, state)) : await db.with(main).select().from(main),
3 replies
DTDrizzle Team
Created by carlos on 5/1/2023 in #help
inArray
i don't want to do this :/
const main = db.$with('main').as(
db
.select({
id: histories.id,
medicalHistoryNumber: histories.medicalHistoryNumber,
date: histories.date,
type: histories.type,
division: histories.division,
state: histories.state,
provider: {
id: provider.id,
name: provider.name,
},
hospital: {
id: hospital.id,
name: hospital.name,
},
})
.from(histories)
.leftJoin(hospital, eq(histories.hospitalId, hospital.id))
.leftJoin(provider, eq(histories.providerId, provider.id))
.where(or(eq(histories.hospitalId, req.session.user?.hospitalId!), eq(histories.providerId, req.session.user?.providerId!)))
.orderBy(desc(histories.id))
.limit(Number(limit))
.offset(Number(offset)),
);
const main = db.$with('main').as(
db
.select({
id: histories.id,
medicalHistoryNumber: histories.medicalHistoryNumber,
date: histories.date,
type: histories.type,
division: histories.division,
state: histories.state,
provider: {
id: provider.id,
name: provider.name,
},
hospital: {
id: hospital.id,
name: hospital.name,
},
})
.from(histories)
.leftJoin(hospital, eq(histories.hospitalId, hospital.id))
.leftJoin(provider, eq(histories.providerId, provider.id))
.where(or(eq(histories.hospitalId, req.session.user?.hospitalId!), eq(histories.providerId, req.session.user?.providerId!)))
.orderBy(desc(histories.id))
.limit(Number(limit))
.offset(Number(offset)),
);
3 replies
DTDrizzle Team
Created by carlos on 4/16/2023 in #help
I think i have found another bug
why?
4 replies
DTDrizzle Team
Created by carlos on 4/16/2023 in #help
I think i have found another bug
4 replies
DTDrizzle Team
Created by carlos on 4/16/2023 in #help
I think i have found another bug
if i try do this, that is correctly done i guess.. i get this error
4 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
thanks man!
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
upgraded again and now its fixed!
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
now the enum is converted to string instead of enum
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
still same error
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
i updated to:
- drizzle-orm 0.23.8
+ drizzle-orm 0.23.13
- drizzle-orm 0.23.8
+ drizzle-orm 0.23.13
26 replies
DTDrizzle Team
Created by carlos on 4/11/2023 in #help
Enums
great! in the meantime ill just hardcode the values
26 replies