inArray

For what i've seen pass an empty array to inArray is not supported, how to you handle this cases? using "with" queries and adding it conditonally? or how?
1 Reply
Charlie
CharlieOP2y ago
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)),
);
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),
Want results from more Discord servers?
Add your server