如何在毛毛雨orm

问题描述 投票:0回答:1

表的防御:

export const incident = pgTable('incidents', { id: serial('id').primaryKey(), title: text('title').notNull(), }); export const incidentUpdates = pgTable('incident_updates', { id: serial('id').primaryKey(), incidentId: integer('incident_id').references(() => incidents.id), description: text('description').notNull(), lastUpdatedTimestamp: timestamp('last_updated_timestamp').defaultNow(), status: text('status').notNull(), });

问题:

我如何使用drizzle orm无需求助于RAW SQL,可以复制上述SQL查询,该查询选择最新的IDDIST_UPDATE,每个事件中的最新Inscort_update?有没有办法使用Drizzle的查询构建器方法执行此查询类型? -stack:

postgresql,毛毛雨orm,typescript

我只是在教程中看到了一个例子。 我在这里粘贴了教程的示例:

sql postgresql orm drizzle drizzle-orm
1个回答
0
投票

在您的情况下,这将是类似的事情,但可使用的是事件,并且用户限制可以是INDAST_UPDATES,并且左联接条件将在事件中。ID和INDACT_UPDATES.incident.Incident_ID.

const result = await db .select({ id: incidents.id, title: incidents.title, description: incident_updates.description, last_updated_timestamp: incident_updates.last_updated_timestamp, }) .from(incidents) .leftJoin( incident_updates, eq(incident_updates.incident_id, incidents.id) ); enter image description here 在您的情况下,我可能会使用此处描述的别名:

https://orm.drizzle.team/docs/joins#aliases-selfjoins

当您的左键内有更多特定条件 (使用。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.