Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
15 replies
Ares

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;
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Join through another table
SupabaseSSupabase / help-and-questions
4y ago
Query foreign table twice, once directly, once through join table
SupabaseSSupabase / help-and-questions
4y ago
Table size and full text search performance
SupabaseSSupabase / help-and-questions
4y ago
How to search across multiple columns and tables
SupabaseSSupabase / help-and-questions
4y ago