neosqlite 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "neosqlite",
3
3
  "description": "A lightweight wrapper around better-sqlite3 that adds developer-friendly features like job scheduling, migrations, error handling, query logging, SQL utilities, and more",
4
- "version": "1.0.18",
4
+ "version": "1.0.20",
5
5
  "main": "lib/src/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
@@ -24,7 +24,7 @@ class NeosqliteJobs {
24
24
  return this.options?.maxJobs ?? 10;
25
25
  }
26
26
  get processEvery() {
27
- return this.options?.processEvery ?? 5000;
27
+ return this.options?.processEvery ?? 5_000;
28
28
  }
29
29
  get maxRetries() {
30
30
  return this.options?.maxRetries ?? 3;
@@ -117,7 +117,7 @@ class NeosqliteJobs {
117
117
  // Prevent multiple cron jobs from getting scheduled for the same dates
118
118
  this.db.write(`CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.jobsTable}_name_cron_runAt ON ${this.jobsTable} (name, cron, runAt)`);
119
119
  // Only allow cron jobs to have one scheduled run at a time, so that updating a crons syntax is easier, and immediately updates
120
- this.db.write(`CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.jobsTable}_name_cron_status ON ${this.jobsTable} (name, cron, status) WHERE cron IS NOT NULL;`);
120
+ this.db.write(`CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.jobsTable}_name_cron_status ON ${this.jobsTable} (name, cron, status) WHERE cron IS NOT NULL AND status IN ('${types_1.JobStatus.Pending}');`);
121
121
  // Allow faster querying of pending jobs
122
122
  this.db.write(`CREATE INDEX IF NOT EXISTS idx_${this.jobsTable}_status_runAt_priority ON ${this.jobsTable} (status, runAt, priority DESC)`);
123
123
  }
@@ -170,7 +170,7 @@ class NeosqliteJobs {
170
170
  try {
171
171
  await Promise.resolve(handler.onRun());
172
172
  this.db.write({
173
- sql: (0, util_1.queryString)("UPDATE " + this.jobsTable, "SET status = :status, updatedAt = CURRENT_TIMESTAMP", "WHERE id = :id"),
173
+ sql: "UPDATE " + this.jobsTable + " SET status = :status, updatedAt = CURRENT_TIMESTAMP WHERE id = :id",
174
174
  args: { id, status: types_1.JobStatus.Completed },
175
175
  });
176
176
  // If this is a cronjob, schedule the next run
@@ -195,7 +195,7 @@ class NeosqliteJobs {
195
195
  sql: (0, util_1.queryString)("UPDATE " + this.jobsTable, "SET status = :status, updatedAt = CURRENT_TIMESTAMP", "WHERE id = :id"),
196
196
  args: { id, status: updatedStatus },
197
197
  });
198
- if (updatedStatus === types_1.JobStatus.Failed && handler.onFailure) {
198
+ if (handler.onFailure) {
199
199
  await Promise.resolve(handler.onFailure(err));
200
200
  }
201
201
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "neosqlite",
3
3
  "description": "A lightweight wrapper around better-sqlite3 that adds developer-friendly features like job scheduling, migrations, error handling, query logging, SQL utilities, and more",
4
- "version": "1.0.18",
4
+ "version": "1.0.20",
5
5
  "main": "lib/src/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
package/src/jobs/index.ts CHANGED
@@ -30,7 +30,7 @@ export class NeosqliteJobs {
30
30
  }
31
31
 
32
32
  private get processEvery() {
33
- return this.options?.processEvery ?? 5000;
33
+ return this.options?.processEvery ?? 5_000;
34
34
  }
35
35
 
36
36
  private get maxRetries() {
@@ -165,7 +165,7 @@ export class NeosqliteJobs {
165
165
 
166
166
  // Only allow cron jobs to have one scheduled run at a time, so that updating a crons syntax is easier, and immediately updates
167
167
  this.db.write(
168
- `CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.jobsTable}_name_cron_status ON ${this.jobsTable} (name, cron, status) WHERE cron IS NOT NULL;`,
168
+ `CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.jobsTable}_name_cron_status ON ${this.jobsTable} (name, cron, status) WHERE cron IS NOT NULL AND status IN ('${JobStatus.Pending}');`,
169
169
  );
170
170
 
171
171
  // Allow faster querying of pending jobs
@@ -245,7 +245,7 @@ export class NeosqliteJobs {
245
245
  await Promise.resolve(handler.onRun());
246
246
 
247
247
  this.db.write({
248
- sql: queryString("UPDATE " + this.jobsTable, "SET status = :status, updatedAt = CURRENT_TIMESTAMP", "WHERE id = :id"),
248
+ sql: "UPDATE " + this.jobsTable + " SET status = :status, updatedAt = CURRENT_TIMESTAMP WHERE id = :id",
249
249
  args: { id, status: JobStatus.Completed },
250
250
  });
251
251
 
@@ -277,7 +277,7 @@ export class NeosqliteJobs {
277
277
  args: { id, status: updatedStatus },
278
278
  });
279
279
 
280
- if (updatedStatus === JobStatus.Failed && handler.onFailure) {
280
+ if (handler.onFailure) {
281
281
  await Promise.resolve(handler.onFailure(err as Error));
282
282
  }
283
283
  }