When you build a SQL string by joining it to user input, the input can change the query. A search for a name becomes, with the right text, a query that returns every row. OWASP calls this Injection (A05:2025); the SQL case is CWE-89.
Escaping quotes by hand looks like a fix and is not one: there is always another way in. The real fix keeps the data out of the SQL text. Use a parameterized query, where the input is sent as a value bound to a placeholder ($1, $2), never spliced into the string. In this course env.db.raw(sql) splices the string, so it is vulnerable; env.db.query(sql, params) binds the values, so it is safe. Each lab swaps one for the other and keeps the ordinary search working.
Bind the input as a parameter. The database treats it as a value, never as query text.