neosqlite 1.0.15 → 1.0.16

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.15",
4
+ "version": "1.0.16",
5
5
  "main": "lib/src/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
@@ -21,12 +21,15 @@ const runQuery = (config, params, fn) => {
21
21
  const result = fn();
22
22
  const endTime = process.hrtime(startTime);
23
23
  const endTimeMs = endTime[0] * 1_000 + endTime[1] / 1_000_000;
24
- if (config.onQueryComplete || config.onQueryLog) {
24
+ if (config.onQueryComplete || config.onQueryLog || config.onQueryTime) {
25
25
  const queryString = (0, exports.getFullQueryString)(params);
26
26
  config.onQueryComplete?.({ query: queryString, time: endTimeMs });
27
27
  if (typeof params === "object" && params.logQuery) {
28
28
  config.onQueryLog?.(queryString);
29
29
  }
30
+ if (typeof params === "object" && params.timeQuery) {
31
+ config.onQueryTime?.(endTimeMs);
32
+ }
30
33
  }
31
34
  return result;
32
35
  };
@@ -4,6 +4,8 @@ export type NeosqliteConfig = {
4
4
  file: ":memory:" | string;
5
5
  /** When a query is logged using `logQuery: true`, you will receive the full query string via this callback */
6
6
  onQueryLog?: (query: string) => void;
7
+ /** When a query is timed using `timeQuery: true` you will receive the full query time via this callback (in ms) */
8
+ onQueryTime?: (time: number) => void;
7
9
  /** When a query finishes, gather data about the query from this callback */
8
10
  onQueryComplete?: (data: OnQueryFinishData) => void;
9
11
  };
@@ -39,6 +41,8 @@ export type OnQueryFinishData = {
39
41
  export type QueryParams = {
40
42
  /** The SQL query to execute */
41
43
  sql: string;
44
+ /** When true, logs the time that a query took to onQuery */
45
+ timeQuery?: boolean;
42
46
  /** When true, the query string will be sent to onQueryLog */
43
47
  logQuery?: boolean;
44
48
  /** The values to bind to the query string */
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.15",
4
+ "version": "1.0.16",
5
5
  "main": "lib/src/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
@@ -25,7 +25,7 @@ export const runQuery = (config: NeosqliteConfig, params: ExecuteQueryParams, fn
25
25
  const endTime = process.hrtime(startTime);
26
26
  const endTimeMs = endTime[0] * 1_000 + endTime[1] / 1_000_000;
27
27
 
28
- if (config.onQueryComplete || config.onQueryLog) {
28
+ if (config.onQueryComplete || config.onQueryLog || config.onQueryTime) {
29
29
  const queryString = getFullQueryString(params);
30
30
 
31
31
  config.onQueryComplete?.({ query: queryString, time: endTimeMs });
@@ -33,6 +33,10 @@ export const runQuery = (config: NeosqliteConfig, params: ExecuteQueryParams, fn
33
33
  if (typeof params === "object" && params.logQuery) {
34
34
  config.onQueryLog?.(queryString);
35
35
  }
36
+
37
+ if (typeof params === "object" && params.timeQuery) {
38
+ config.onQueryTime?.(endTimeMs);
39
+ }
36
40
  }
37
41
 
38
42
  return result;
package/src/types.ts CHANGED
@@ -7,6 +7,9 @@ export type NeosqliteConfig = {
7
7
  /** When a query is logged using `logQuery: true`, you will receive the full query string via this callback */
8
8
  onQueryLog?: (query: string) => void;
9
9
 
10
+ /** When a query is timed using `timeQuery: true` you will receive the full query time via this callback (in ms) */
11
+ onQueryTime?: (time: number) => void;
12
+
10
13
  /** When a query finishes, gather data about the query from this callback */
11
14
  onQueryComplete?: (data: OnQueryFinishData) => void;
12
15
  };
@@ -52,6 +55,9 @@ export type QueryParams = {
52
55
  /** The SQL query to execute */
53
56
  sql: string;
54
57
 
58
+ /** When true, logs the time that a query took to onQuery */
59
+ timeQuery?: boolean;
60
+
55
61
  /** When true, the query string will be sent to onQueryLog */
56
62
  logQuery?: boolean;
57
63