yasserconnect
yasserconnect
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
it works, thanks a lot @Raphaël M (@rphlmr) ⚡ 😍
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
export const shipment = pgTable('Shipment', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
bayanNO: text('bayanNO').notNull(),
manifestNO: text('manifestNO').notNull(),
importerName: text('importerName').notNull(),
declarantName: text('declarantName'),
importerPhone: text('importerPhone'),
declarantPhone: text('declarantPhone'),
bookmarkIds: text('bookmarkIds').array(),
note: text('note'),
portName: text('portName'),
...
}, (table) => ({
createdAtIdx: index('shipment_created_at_idx').on(table.createdAt),
}));
export const shipment = pgTable('Shipment', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
bayanNO: text('bayanNO').notNull(),
manifestNO: text('manifestNO').notNull(),
importerName: text('importerName').notNull(),
declarantName: text('declarantName'),
importerPhone: text('importerPhone'),
declarantPhone: text('declarantPhone'),
bookmarkIds: text('bookmarkIds').array(),
note: text('note'),
portName: text('portName'),
...
}, (table) => ({
createdAtIdx: index('shipment_created_at_idx').on(table.createdAt),
}));
is this correct?
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
export const shipmentRelations = relations(shipment, ({ one, many }) => ({
products: many(product),
}));
export const shipmentRelations = relations(shipment, ({ one, many }) => ({
products: many(product),
}));
export const productRelations = relations(product, ({ one }) => ({
shipment: one(shipment, {
fields: [product.shipmentId],
references: [shipment.id],
}),
}));
export const productRelations = relations(product, ({ one }) => ({
shipment: one(shipment, {
fields: [product.shipmentId],
references: [shipment.id],
}),
}));
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
export const shipment = pgTable('Shipment', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
bayanNO: text('bayanNO').notNull(),
manifestNO: text('manifestNO').notNull(),
importerName: text('importerName').notNull(),
declarantName: text('declarantName'),
importerPhone: text('importerPhone'),
declarantPhone: text('declarantPhone'),
bookmarkIds: text('bookmarkIds').array(),
note: text('note'),
portName: text('portName'),
...
});
export const shipment = pgTable('Shipment', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
bayanNO: text('bayanNO').notNull(),
manifestNO: text('manifestNO').notNull(),
importerName: text('importerName').notNull(),
declarantName: text('declarantName'),
importerPhone: text('importerPhone'),
declarantPhone: text('declarantPhone'),
bookmarkIds: text('bookmarkIds').array(),
note: text('note'),
portName: text('portName'),
...
});
export const product = pgTable('Product', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
shipmentId: text('shipmentId')
.notNull()
.references(() => shipment.id, {
onDelete: 'cascade',
onUpdate: 'cascade',
}),
item: text('item').notNull(),
weight: doublePrecision('weight').notNull(),
status: text('status').notNull(),
countryOrigin: text('countryOrigin').notNull(),
rejectReason: text('rejectReason'),
rejectDetail: text('rejectDetail'),
hsCode: text('hsCode'),
sampleName: text('sampleName'),
...
});
export const product = pgTable('Product', {
id: varchar('id')
.$defaultFn(() => generateId())
.primaryKey(),
createdAt: timestamp('createdAt', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updatedAt', {
precision: 6,
withTimezone: true,
})
.notNull()
.$onUpdate(() => new Date()),
userId: text('userId')
.notNull()
.references(() => user.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
shipmentId: text('shipmentId')
.notNull()
.references(() => shipment.id, {
onDelete: 'cascade',
onUpdate: 'cascade',
}),
item: text('item').notNull(),
weight: doublePrecision('weight').notNull(),
status: text('status').notNull(),
countryOrigin: text('countryOrigin').notNull(),
rejectReason: text('rejectReason'),
rejectDetail: text('rejectDetail'),
hsCode: text('hsCode'),
sampleName: text('sampleName'),
...
});
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
that what i thought, but i never do it before.. can you guide me?
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
yup, but it take too long until return the data, if i remove orderBy it works normally! it takes more than 3 min with orderBy! and few second without !
17 replies
DTDrizzle Team
Created by yasserconnect on 8/1/2024 in #help
[BUG]: orderBy causes relational query to fail
const shipmentQuery = await db.query.shipment.findMany({
with: {
products: true,
},
limit: 10,
orderBy: desc(shipment.createdAt),
});
const shipmentQuery = await db.query.shipment.findMany({
with: {
products: true,
},
limit: 10,
orderBy: desc(shipment.createdAt),
});
thank you for share.. So how can i use it orderBy, i just want to order shipments by createdAt?
17 replies
DTDrizzle Team
Created by yasserconnect on 7/5/2024 in #help
use limit or undefined
nice, i don't know about 0 i was use undefined.. thank you.
12 replies