Build queries dynamically with conditions.

Ssubhendupsingh5/19/2023
How to build query on the basis of if-else conditions? I have tried doing it as below
let dbQuery = db.select().from(orders).where(and(eq(orders.organizationId, orgId), ne(orders.orderStatus , "CART"), eq(orders.id, Number(query))));

if( status ){
            if(status == "COMPLETE")
                dbQuery.where(eq(orders.orderStatus, "COMPLETE"));
            else if(status == "PROCESSING")
                dbQuery.where(eq(orders.orderStatus, "PROCESSING"));
            else if(status == "CANCELLED")
                dbQuery.where(eq(orders.orderStatus, "CANCELLED"));
        }

But the where conditions don't seem to add and the result is returned without them.
Ssubhendupsingh5/19/2023
Thanks, it worked!