neosqlite 1.0.8 → 1.0.10
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 +1 -1
- package/lib/src/client/index.js +7 -0
- package/lib/src/jobs/index.d.ts +2 -2
- package/lib/src/jobs/index.js +4 -4
- package/lib/src/types.d.ts +3 -1
- package/package.json +1 -1
- package/src/client/index.ts +8 -0
- package/src/jobs/index.ts +5 -5
- package/src/types.ts +4 -1
- package/database.db +0 -0
- package/index.ts +0 -14
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.
|
|
4
|
+
"version": "1.0.10",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
package/lib/src/client/index.js
CHANGED
|
@@ -63,6 +63,12 @@ function createClient(config) {
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Executes all of the table creation code, separated by semicolons
|
|
68
|
+
*/
|
|
69
|
+
const createTableFromSchema = (string) => {
|
|
70
|
+
return (0, util_1.runQuery)(config, string, () => db.exec(string));
|
|
71
|
+
};
|
|
66
72
|
return {
|
|
67
73
|
read,
|
|
68
74
|
readOne,
|
|
@@ -70,6 +76,7 @@ function createClient(config) {
|
|
|
70
76
|
batchWrite,
|
|
71
77
|
transaction,
|
|
72
78
|
writeReturning,
|
|
79
|
+
createTableFromSchema,
|
|
73
80
|
pragma: db.pragma.bind(db),
|
|
74
81
|
backup: db.backup.bind(db),
|
|
75
82
|
};
|
package/lib/src/jobs/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CreateJobsOptions, JobOptions, NeosqliteClient } from "../types";
|
|
2
2
|
export declare class NeosqliteJobs {
|
|
3
3
|
private db;
|
|
4
|
-
private options
|
|
4
|
+
private options?;
|
|
5
5
|
private jobsRegistry;
|
|
6
6
|
private activeJobs;
|
|
7
7
|
private isRunning;
|
|
8
|
-
constructor(db: NeosqliteClient, options
|
|
8
|
+
constructor(db: NeosqliteClient, options?: CreateJobsOptions | undefined);
|
|
9
9
|
private get jobsTable();
|
|
10
10
|
private get maxJobs();
|
|
11
11
|
private get processEvery();
|
package/lib/src/jobs/index.js
CHANGED
|
@@ -18,16 +18,16 @@ class NeosqliteJobs {
|
|
|
18
18
|
this.isRunning = false;
|
|
19
19
|
}
|
|
20
20
|
get jobsTable() {
|
|
21
|
-
return this.options
|
|
21
|
+
return this.options?.jobsTable ?? "jobs";
|
|
22
22
|
}
|
|
23
23
|
get maxJobs() {
|
|
24
|
-
return this.options
|
|
24
|
+
return this.options?.maxJobs ?? 10;
|
|
25
25
|
}
|
|
26
26
|
get processEvery() {
|
|
27
|
-
return this.options
|
|
27
|
+
return this.options?.processEvery ?? 5000;
|
|
28
28
|
}
|
|
29
29
|
get maxRetries() {
|
|
30
|
-
return this.options
|
|
30
|
+
return this.options?.maxRetries ?? 3;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Setup tables and start the job worker for neosqlite jobs
|
package/lib/src/types.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export type NeosqliteClient = {
|
|
|
27
27
|
changes: number;
|
|
28
28
|
lastInsertedRowid: number;
|
|
29
29
|
};
|
|
30
|
+
/** Create a table from a schema. Takes multiple statements separated by semicolons, with no parameters */
|
|
31
|
+
createTableFromSchema: (string: string) => void;
|
|
30
32
|
};
|
|
31
33
|
export type OnQueryFinishData = {
|
|
32
34
|
/** The query that was executed */
|
|
@@ -61,7 +63,7 @@ export interface CliCommandOptions extends NeosqliteConfig {
|
|
|
61
63
|
/** The name of the table to store migrations in. Defaults to "migrations" */
|
|
62
64
|
migrationTable?: string;
|
|
63
65
|
}
|
|
64
|
-
export interface CreateJobsOptions
|
|
66
|
+
export interface CreateJobsOptions {
|
|
65
67
|
/** The name of the table to store jobs in. Defaults to "jobs" */
|
|
66
68
|
jobsTable?: string;
|
|
67
69
|
/** How often to process jobs in milliseconds. Defaults to 5000 */
|
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.
|
|
4
|
+
"version": "1.0.10",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
package/src/client/index.ts
CHANGED
|
@@ -73,6 +73,13 @@ export function createClient(config: NeosqliteConfig): NeosqliteClient {
|
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Executes all of the table creation code, separated by semicolons
|
|
78
|
+
*/
|
|
79
|
+
const createTableFromSchema = (string: string) => {
|
|
80
|
+
return runQuery(config, string, () => db.exec(string));
|
|
81
|
+
};
|
|
82
|
+
|
|
76
83
|
return {
|
|
77
84
|
read,
|
|
78
85
|
readOne,
|
|
@@ -80,6 +87,7 @@ export function createClient(config: NeosqliteConfig): NeosqliteClient {
|
|
|
80
87
|
batchWrite,
|
|
81
88
|
transaction,
|
|
82
89
|
writeReturning,
|
|
90
|
+
createTableFromSchema,
|
|
83
91
|
pragma: db.pragma.bind(db),
|
|
84
92
|
backup: db.backup.bind(db),
|
|
85
93
|
};
|
package/src/jobs/index.ts
CHANGED
|
@@ -20,23 +20,23 @@ export class NeosqliteJobs {
|
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
22
|
private db: NeosqliteClient,
|
|
23
|
-
private options
|
|
23
|
+
private options?: CreateJobsOptions,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
26
|
private get jobsTable() {
|
|
27
|
-
return this.options
|
|
27
|
+
return this.options?.jobsTable ?? "jobs";
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private get maxJobs() {
|
|
31
|
-
return this.options
|
|
31
|
+
return this.options?.maxJobs ?? 10;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
private get processEvery() {
|
|
35
|
-
return this.options
|
|
35
|
+
return this.options?.processEvery ?? 5000;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
private get maxRetries() {
|
|
39
|
-
return this.options
|
|
39
|
+
return this.options?.maxRetries ?? 3;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
package/src/types.ts
CHANGED
|
@@ -35,6 +35,9 @@ export type NeosqliteClient = {
|
|
|
35
35
|
|
|
36
36
|
/** Write data to the database, returns the number of rows affected */
|
|
37
37
|
write: (params: ExecuteQueryParams) => { changes: number; lastInsertedRowid: number };
|
|
38
|
+
|
|
39
|
+
/** Create a table from a schema. Takes multiple statements separated by semicolons, with no parameters */
|
|
40
|
+
createTableFromSchema: (string: string) => void;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export type OnQueryFinishData = {
|
|
@@ -81,7 +84,7 @@ export interface CliCommandOptions extends NeosqliteConfig {
|
|
|
81
84
|
migrationTable?: string;
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
export interface CreateJobsOptions
|
|
87
|
+
export interface CreateJobsOptions {
|
|
85
88
|
/** The name of the table to store jobs in. Defaults to "jobs" */
|
|
86
89
|
jobsTable?: string;
|
|
87
90
|
|
package/database.db
DELETED
|
Binary file
|
package/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createClient } from "./src/client";
|
|
2
|
-
|
|
3
|
-
const db = createClient({
|
|
4
|
-
file: "database.db",
|
|
5
|
-
onQueryLog: (log) => {
|
|
6
|
-
console.debug(log);
|
|
7
|
-
},
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
db.write("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");
|
|
11
|
-
|
|
12
|
-
const result = db.readOne("SELECT * FROM users");
|
|
13
|
-
|
|
14
|
-
console.log(result);
|