search through table
Hi, I have only one table with a couple of columns I want to search and was wondering if my approach is something you would do.
let query = supabase
.from('adverts')
.select(
`advert_id, advert_title, advert_description, advert_category_id, advert_sub_category_id, advert_sub_sub_category_id, zip_code, location, state, is_highlighted, update_prio, advert_images(image_url, is_main_image, is_deleted)`
)
.eq('advert_images.is_deleted', false)
.eq('advert_images.is_main_image', true)
.eq('is_expired', false)
.eq('is_paid', true)
.eq('is_active', true);
let state = null;
let location = null;
let zipCode = null;
let categoryLabel = 'something';
if (state) {
query = query.ilike('state', state);
}
if (location) {
query = query.ilike('location', location);
}
if (zipCode) {
query = query.ilike('zip_code', zipCode);
}
if (categoryLabel) {
const category = findCategoryByLabel(categoryLabel, advertCategories);
if (category) {
query = query.eq('advert_category_id', category.id);
}
}
const { data: adverts, error: advertsError } = await query;let query = supabase
.from('adverts')
.select(
`advert_id, advert_title, advert_description, advert_category_id, advert_sub_category_id, advert_sub_sub_category_id, zip_code, location, state, is_highlighted, update_prio, advert_images(image_url, is_main_image, is_deleted)`
)
.eq('advert_images.is_deleted', false)
.eq('advert_images.is_main_image', true)
.eq('is_expired', false)
.eq('is_paid', true)
.eq('is_active', true);
let state = null;
let location = null;
let zipCode = null;
let categoryLabel = 'something';
if (state) {
query = query.ilike('state', state);
}
if (location) {
query = query.ilike('location', location);
}
if (zipCode) {
query = query.ilike('zip_code', zipCode);
}
if (categoryLabel) {
const category = findCategoryByLabel(categoryLabel, advertCategories);
if (category) {
query = query.eq('advert_category_id', category.id);
}
}
const { data: adverts, error: advertsError } = await query;