@an5/orm 1.0.3 → 1.0.4
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.
|
@@ -25,7 +25,7 @@ class PythonGenerator {
|
|
|
25
25
|
pyContent += 'MODEL_FIELDS = {\n';
|
|
26
26
|
for (const model of models) {
|
|
27
27
|
const props = this.getAllPropertyVariations(model.name);
|
|
28
|
-
const fieldsStr =
|
|
28
|
+
const fieldsStr = this.formatFields(model);
|
|
29
29
|
for (const prop of props) {
|
|
30
30
|
pyContent += ` "${prop}": ${fieldsStr},\n`;
|
|
31
31
|
}
|
|
@@ -68,6 +68,14 @@ class PythonGenerator {
|
|
|
68
68
|
}
|
|
69
69
|
return Array.from(variations);
|
|
70
70
|
}
|
|
71
|
+
formatFields(model) {
|
|
72
|
+
if (model.fields.length === 0)
|
|
73
|
+
return '[]';
|
|
74
|
+
const fields = model.fields.map(f => {
|
|
75
|
+
return ` { "name": "${f.name}", "type": "${f.type}${f.isOptional ? '?' : ''}", "sql": "${f.sqlType}", "isOptional": ${f.isOptional ? 'True' : 'False'}, "hasDefault": ${f.hasDefault ? 'True' : 'False'}, "isId": ${f.isId ? 'True' : 'False'} }`;
|
|
76
|
+
});
|
|
77
|
+
return `[\n${fields.join(',\n')}\n ]`;
|
|
78
|
+
}
|
|
71
79
|
toCamelCase(str) {
|
|
72
80
|
if (!str)
|
|
73
81
|
return '';
|
|
@@ -20,13 +20,13 @@ export class PythonGenerator {
|
|
|
20
20
|
pyContent += '}\n\n';
|
|
21
21
|
|
|
22
22
|
// 2. MODEL_FIELDS
|
|
23
|
-
pyContent += 'MODEL_FIELDS = {\n';
|
|
24
|
-
for (const model of models) {
|
|
25
|
-
const props = this.getAllPropertyVariations(model.name);
|
|
26
|
-
const fieldsStr =
|
|
27
|
-
for (const prop of props) {
|
|
28
|
-
pyContent += ` "${prop}": ${fieldsStr},\n`;
|
|
29
|
-
}
|
|
23
|
+
pyContent += 'MODEL_FIELDS = {\n';
|
|
24
|
+
for (const model of models) {
|
|
25
|
+
const props = this.getAllPropertyVariations(model.name);
|
|
26
|
+
const fieldsStr = this.formatFields(model);
|
|
27
|
+
for (const prop of props) {
|
|
28
|
+
pyContent += ` "${prop}": ${fieldsStr},\n`;
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
pyContent += '}\n\n';
|
|
32
32
|
|
|
@@ -54,7 +54,7 @@ export class PythonGenerator {
|
|
|
54
54
|
fs.writeFileSync(this.outputPath, pyContent);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
private getAllPropertyVariations(modelName: string): string[] {
|
|
57
|
+
private getAllPropertyVariations(modelName: string): string[] {
|
|
58
58
|
const variations = new Set<string>();
|
|
59
59
|
|
|
60
60
|
// 1. camelCase (User -> user, McpServer -> mcpServer)
|
|
@@ -73,9 +73,19 @@ export class PythonGenerator {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
return Array.from(variations);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private formatFields(model: Model): string {
|
|
79
|
+
if (model.fields.length === 0) return '[]';
|
|
80
|
+
|
|
81
|
+
const fields = model.fields.map(f => {
|
|
82
|
+
return ` { "name": "${f.name}", "type": "${f.type}${f.isOptional ? '?' : ''}", "sql": "${f.sqlType}", "isOptional": ${f.isOptional ? 'True' : 'False'}, "hasDefault": ${f.hasDefault ? 'True' : 'False'}, "isId": ${f.isId ? 'True' : 'False'} }`;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return `[\n${fields.join(',\n')}\n ]`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private toCamelCase(str: string): string {
|
|
79
89
|
if (!str) return '';
|
|
80
90
|
return str[0].toLowerCase() + str.slice(1);
|
|
81
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@an5/orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "The lightweight ORM for SQL Server with support for TypeScript, Python, and .NET (C#).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test:generator": "node test/generator.test.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@an5/adapters": "^0.
|
|
38
|
+
"@an5/adapters": "^0.2.0",
|
|
39
39
|
"bcryptjs": "^2.4.3",
|
|
40
40
|
"dotenv": "^16.4.5",
|
|
41
41
|
"mssql": "^12.5.5"
|