When / Conditionals
Was this helpful?
Was this helpful?
query.from( "posts" )
.when(
someFlag,
function( q ) {
q.orderBy( "published_date", "desc" );
},
function( q ) {
q.orderBy( "modified_date", "desc" );
}
);qb.from( "users" )
.where( "active", 1 )
.when( len( url.q ), function( q ) {
q.where( "username", "LIKE", q & "%" )
.orWhere( "email", "LIKE", q & "%" );
} );SELECT *
FROM "users"
WHERE "active" = ?
AND (
"username" = ?
OR "email" = ?
)