@stacksjs/orm 0.61.20 → 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.
Files changed (3) hide show
  1. package/dist/index.js +1978 -1418
  2. package/package.json +1 -1
  3. package/src/utils.ts +17 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/orm",
3
3
  "type": "module",
4
- "version": "0.61.20",
4
+ "version": "0.61.21",
5
5
  "description": "The Stacks ORM integration",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
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')