Skip to content

Commit

Permalink
Optimize query execution in SQLiteHelper
Browse files Browse the repository at this point in the history
- Modified `executeQuery` method to use `db.exec` for queries without parameters.
- Retained `db.prepare` with `stmt.run` for queries with parameters.
- Improves performance by avoiding unnecessary statement preparation for simple queries.
  • Loading branch information
dimaslanjaka committed Jan 27, 2025
1 parent bd8bce1 commit a75c2c7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/SQLiteHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ class SQLiteHelper {
*/
executeQuery(sql, params = []) {
try {
const stmt = this.db.prepare(sql);
stmt.run(...params);
if (params.length > 0) {
const stmt = this.db.prepare(sql);
stmt.run(...params);
} else {
this.db.exec(sql);
}
} catch (err) {
console.error(`Error executing query: ${sql}`, err.message);
throw err;
Expand Down

0 comments on commit a75c2c7

Please sign in to comment.