#Proper startsWith sql query

1 messages · Page 1 of 1 (latest)

opaque crescent
#

Ask ChatGPT for help with SQL, it makes it much easier to figure out

opaque crescent
#
// 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;
  }
}
limber escarp
#

Does replace with g do the same thing as replaceAll tho

#

Oh, it does

#

Thanks