@glmachado/any-store 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +6 -4
  2. package/readme.md +59 -0
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@glmachado/any-store",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
9
  "module": "./dist/lib.js",
10
+ "types": "./dist/src/lib.d.ts",
10
11
  "exports": {
11
12
  ".": {
12
- "import": "./dist/any-store.es.js",
13
+ "import": "./dist/lib.es.js",
13
14
  "types": "./dist/src/lib.d.ts"
14
15
  }
15
16
  },
@@ -28,10 +29,11 @@
28
29
  "typescript": "~5.9.3",
29
30
  "vite": "npm:rolldown-vite@7.2.5",
30
31
  "vite-plugin-dts": "^4.5.4",
32
+ "@glmachado/any-store": "^0.1.1",
31
33
  "vitest": "^4.0.16"
32
34
  },
33
35
  "overrides": {
34
36
  "vite": "npm:rolldown-vite@7.2.5"
35
- }
37
+ },
38
+ "dependencies": {}
36
39
  }
37
-
package/readme.md ADDED
@@ -0,0 +1,59 @@
1
+ ## Any Store
2
+
3
+ This package provides a simple in memory, embedded database with key-value storage. The main advantage of using this database is that with it you can share data between different threads and workers without the cost of for serialization. Data can be written and read in worker threads and the main thread.
4
+
5
+ ### Usage
6
+
7
+ ```ts
8
+ import { WDB } from "@glmachado/any-store";
9
+
10
+ const db = await WDB.create();
11
+ const table = db.createTable({
12
+ counter: "i32",
13
+ });
14
+ const row = table.row(WDB.i32(1));
15
+
16
+ console.log(row.get("counter")); // null
17
+
18
+ row.update("counter", WDB.i32(0));
19
+ db.commit();
20
+
21
+ console.log(row.get("counter")); // 0
22
+ ```
23
+
24
+ ## Usage with workers
25
+
26
+ ```ts
27
+ // in main thread
28
+ import { WDB } from "@glmachado/any-store";
29
+
30
+ const db = await WDB.create();
31
+ const table = db.createTable({
32
+ counter: "i32",
33
+ });
34
+ const row = table.row(WDB.i32(1));
35
+ row.update("counter", WDB.i32(10));
36
+ db.commit();
37
+
38
+ const worker = new Worker("./example.worker.js");
39
+ worker.postMessage({
40
+ module: db.getModule(),
41
+ memory: db.getMemory(),
42
+ });
43
+ ```
44
+
45
+ ```ts
46
+ // in worker thread
47
+ import { WDB } from "@glmachado/any-store";
48
+
49
+ self.onmessage = async (event) => {
50
+ const module = event.data.module;
51
+ const memory = event.data.memory;
52
+ const db = await WDB.fromModule(module, memory, 1);
53
+
54
+ //this will read data from the table created in the main thread
55
+ const table = db.getTable(1, { counter: "i32" });
56
+ const row = table.row(WDB.i32(1));
57
+ console.log(row.get("counter")); // 10
58
+ };
59
+ ```