if i have an array of primary keys, how

if i have an array of primary keys, how do i search using IN? will this work? or do i need to format the array to a comma delimited string? const { results: usersFromUserIds } = await this.env.DB.prepare( SELECT * FROM user WHERE _id IN (?1) ) .bind(uniqueUserIds) .all()
1 Reply
Gagan Suie
Gagan SuieOP12mo ago
solved it by doing something like: // Generate placeholders let placeholders = activeUserIds.map((_, index) => '?' + (index + 1)).join(',') // Use placeholders in the query and bind values const { results: guests } = await this.env.DB.prepare( SELECT user.*, plan.planTier FROM user LEFT JOIN plan ON user._id = plan.userId WHERE user._id IN (${placeholders}) ) .bind(...activeUserIds) .all()
Want results from more Discord servers?
Add your server