node-sqlite-kv 0.2.1 → 0.2.2
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/dist/index.js +18 -2
- package/dist/index.mjs +8 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
|
|
21
31
|
// src/index.ts
|
|
@@ -29,6 +39,8 @@ module.exports = __toCommonJS(index_exports);
|
|
|
29
39
|
// src/structures/KVSync.ts
|
|
30
40
|
var import_node_sqlite = require("node:sqlite");
|
|
31
41
|
var import_node_v8 = require("node:v8");
|
|
42
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
43
|
+
var import_node_path = __toESM(require("node:path"));
|
|
32
44
|
var KVSync = class {
|
|
33
45
|
static {
|
|
34
46
|
__name(this, "KVSync");
|
|
@@ -39,13 +51,17 @@ var KVSync = class {
|
|
|
39
51
|
* @param path Where the database is stored, or `:memory:` for in-memory storage
|
|
40
52
|
*/
|
|
41
53
|
constructor(options) {
|
|
42
|
-
|
|
54
|
+
const dbPath = options?.path ?? ":memory:";
|
|
55
|
+
if (dbPath !== ":memory:") {
|
|
56
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(dbPath), { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
this.#db = new import_node_sqlite.DatabaseSync(dbPath);
|
|
43
59
|
this.setJournalMode(options?.journalMode ?? "DELETE");
|
|
44
60
|
this.#db.exec(`
|
|
45
61
|
CREATE TABLE IF NOT EXISTS kv (
|
|
46
62
|
key TEXT PRIMARY KEY NOT NULL,
|
|
47
63
|
value BLOB NOT NULL
|
|
48
|
-
) STRICT
|
|
64
|
+
) STRICT;
|
|
49
65
|
`);
|
|
50
66
|
}
|
|
51
67
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,8 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/structures/KVSync.ts
|
|
5
5
|
import { DatabaseSync } from "node:sqlite";
|
|
6
6
|
import { serialize, deserialize } from "node:v8";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
7
9
|
var KVSync = class {
|
|
8
10
|
static {
|
|
9
11
|
__name(this, "KVSync");
|
|
@@ -14,13 +16,17 @@ var KVSync = class {
|
|
|
14
16
|
* @param path Where the database is stored, or `:memory:` for in-memory storage
|
|
15
17
|
*/
|
|
16
18
|
constructor(options) {
|
|
17
|
-
|
|
19
|
+
const dbPath = options?.path ?? ":memory:";
|
|
20
|
+
if (dbPath !== ":memory:") {
|
|
21
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
this.#db = new DatabaseSync(dbPath);
|
|
18
24
|
this.setJournalMode(options?.journalMode ?? "DELETE");
|
|
19
25
|
this.#db.exec(`
|
|
20
26
|
CREATE TABLE IF NOT EXISTS kv (
|
|
21
27
|
key TEXT PRIMARY KEY NOT NULL,
|
|
22
28
|
value BLOB NOT NULL
|
|
23
|
-
) STRICT
|
|
29
|
+
) STRICT;
|
|
24
30
|
`);
|
|
25
31
|
}
|
|
26
32
|
/**
|