@stacksjs/orm 0.61.19 → 0.61.21
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 +1978 -1418
- package/package.json +1 -1
- package/src/utils.ts +17 -0
package/package.json
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { generator, parser, traverse } from '@stacksjs/build'
|
|
2
2
|
import { fs } from '@stacksjs/storage'
|
|
3
|
+
import { path } from '@stacksjs/path'
|
|
3
4
|
import { plural, snakeCase } from '@stacksjs/strings'
|
|
4
5
|
import type { Attributes } from '@stacksjs/types'
|
|
5
6
|
import type { Model } from '@stacksjs/types'
|
|
@@ -14,6 +15,22 @@ export async function modelTableName(model: Model | ModelPath): Promise<string>
|
|
|
14
15
|
return model.table ?? snakeCase(plural(model?.name || ''))
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
export function getModelName(model: Model, modelPath: string): string {
|
|
19
|
+
if (model.name)
|
|
20
|
+
return model.name
|
|
21
|
+
|
|
22
|
+
const baseName = path.basename(modelPath)
|
|
23
|
+
|
|
24
|
+
return baseName.replace(/\.ts$/, '');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getTableName(model: Model, modelPath: string): string {
|
|
28
|
+
if (model.table)
|
|
29
|
+
return model.table
|
|
30
|
+
|
|
31
|
+
return snakeCase(plural(getModelName(model, modelPath)))
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
export async function extractFieldsFromModel(filePath: string) {
|
|
18
35
|
// Read the TypeScript file
|
|
19
36
|
const content = fs.readFileSync(filePath, 'utf8')
|