@wxn0brp/db 0.8.1 → 0.8.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.
@@ -57,6 +57,20 @@ async function processRelations(dbs, cfg, data, parentList = null) {
57
57
  item[as] = result;
58
58
  }
59
59
  }
60
+ else if (type === "11") {
61
+ const cache = new Map();
62
+ for (const item of targets) {
63
+ const id = item[pk];
64
+ if (!cache.has(id)) {
65
+ cache.set(id, await db.findOne(coll, { [fk]: id }, {}, { select }));
66
+ }
67
+ const result = cache.get(id) || null;
68
+ if (result && rel.relations) {
69
+ await processRelations(dbs, rel.relations, result);
70
+ }
71
+ item[as] = result;
72
+ }
73
+ }
60
74
  else if (type === "1n") {
61
75
  const ids = targets.map(i => i[pk]);
62
76
  const results = await db.find(coll, { $in: { [fk]: ids } }, {}, findOpts || {}, { select });
@@ -16,7 +16,7 @@ export declare namespace RelationTypes {
16
16
  as?: string;
17
17
  select?: string[];
18
18
  findOpts?: DbFindOpts;
19
- type?: "1" | "1n" | "nm";
19
+ type?: "1" | "11" | "1n" | "nm";
20
20
  relations?: Relation;
21
21
  through?: {
22
22
  table: string;
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.8.1";
1
+ export const version = "0.8.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "A simple file-based database management system with support for CRUD operations, custom queries, and graph structures.",