Skip to content

Commit ac5406a

Browse files
committed
chore(prisma-parser): create utility to create intermediate table
1 parent ed629d8 commit ac5406a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { type Model } from "@mrleebo/prisma-ast";
2+
3+
import { formatIntermediateTableField } from "./formatIntermediateField";
4+
import { lookForRelation } from "./lookForRelation";
5+
6+
import {
7+
type IntermediateTable,
8+
type RawRelationInfo,
9+
type RelationType,
10+
} from "@/types/intermediateFormattedNode";
11+
import { isField } from "@/utils/isTypeOf";
12+
13+
export const formatIntermediateTable = (
14+
node: Model,
15+
registerRawRelation: (info: RawRelationInfo) => void,
16+
registerInverseRelation: (name: string, info: RelationType) => void,
17+
): IntermediateTable => {
18+
const fields: IntermediateTable["fields"] = [];
19+
20+
for (const mayAField of node.properties) {
21+
if (!isField(mayAField)) continue;
22+
23+
const field = formatIntermediateTableField(mayAField);
24+
lookForRelation(
25+
mayAField,
26+
node.name,
27+
registerRawRelation,
28+
registerInverseRelation,
29+
);
30+
31+
fields.push(field);
32+
}
33+
34+
return {
35+
fields,
36+
name: node.name,
37+
indexes: [], // TODO : also format indexes,
38+
};
39+
};

0 commit comments

Comments
 (0)