#Proper startsWith sql query
1 messages · Page 1 of 1 (latest)
duh 😢
// Assuming db is an instance of a database connection
const startsWithQuery = db.query('SELECT key, value FROM db WHERE key LIKE $prefix ESCAPE \'\\\'');
// usage
export async function list($prefix: string) {
const escapedPrefix = $prefix.replace(/[%_]/g, '\\$&');
try {
const results = await startsWithQuery.all({ $prefix: escapedPrefix });
return results;
} catch (error) {
// Handle the error
console.error('Error executing query:', error);
throw error;
}
}
thanks
Does replace with g do the same thing as replaceAll tho
Oh, it does
Thanks