Skip to content

Consider using ternary operator to simplify code #9

@ecleary

Description

@ecleary

if (product_id) {
queryToUse = `SELECT * FROM questions WHERE product_id = ${product_id} LIMIT ${(page || 1) * (count || 5) - (count || 5)}, ${(count || 5)}`;
} else {
queryToUse = `SELECT * FROM questions LIMIT ${(page || 1) * (count || 5) - (count || 5)}, ${(count || 5)}`;
}

It would be possible to simplify this code and reduce repetition by using a ternary operator inside the query statement instead of putting the query statement inside of a conditional:

`SELECT * FROM questions WHERE ${product_id ? `product_id = ${product_id} ` : ''}LIMIT...`

If we use this format, then we can get by with writing the query only once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions