Skip to content

Commit 05ae57a

Browse files
committed
chore: wip
1 parent a9a650d commit 05ae57a

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

storage/framework/core/database/src/drivers/sqlite.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ok } from '@stacksjs/error-handling'
44
import { modelTableName } from '@stacksjs/orm'
55
import { path } from '@stacksjs/path'
66
import { fs, glob } from '@stacksjs/storage'
7-
import { pluralize, snakeCase } from '@stacksjs/strings'
87
import type { Attribute, Attributes, Model } from '@stacksjs/types'
98
import { checkPivotMigration, fetchOtherModelRelations, getLastMigrationFields, hasTableBeenMigrated, mapFieldTypeToColumnType } from '.'
109

storage/framework/core/orm/src/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { generator, parser, traverse } from '@stacksjs/build'
22
import { fs } from '@stacksjs/storage'
3+
import { plural, snakeCase } from '@stacksjs/strings'
34
import type { Attributes } from '@stacksjs/types'
5+
import type { Model } from '@stacksjs/types'
6+
7+
type ModelPath = string
8+
9+
export async function modelTableName(model: Model | ModelPath): Promise<string> {
10+
if (typeof model === 'string') {
11+
const modelPath = model
12+
model = (await import(model)).default as Model
13+
}
14+
15+
return model.table ?? snakeCase(plural(model.name ?? modelPath.replace(/.*\/(.*)\.ts$/, '$1')))
16+
}
417

518
export async function extractFieldsFromModel(filePath: string) {
619
// Read the TypeScript file

storage/framework/database/models/AccessToken.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ export default {
4646
'`abilities` must be string of either `read`, `write`, `admin`, `read|write`, `read|admin`, `write|admin`, or `read|write|admin`',
4747
},
4848

49-
factory: () => collect(['read', 'write', 'admin', 'read|write', 'read|admin', 'write|admin', 'read|write|admin']).random(),
49+
factory: () =>
50+
collect([
51+
'read',
52+
'write',
53+
'admin',
54+
'read|write',
55+
'read|admin',
56+
'write|admin',
57+
'read|write|admin',
58+
]).random(),
5059
},
5160
},
5261
} satisfies Model

storage/framework/database/models/Project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { collect } from '@stacksjs/collections'
21
import { faker } from '@stacksjs/faker'
32
import type { Model } from '@stacksjs/types'
43
import { schema } from '@stacksjs/validation'
4+
import { collect } from '@stacksjs/collections'
55

66
export default {
77
name: 'Project', // defaults to the sanitized file name
@@ -33,7 +33,7 @@ export default {
3333
message: '`description` must be a string',
3434
},
3535

36-
factory: () => faker.lorem.sentence({ min: 10, max: 10 }),
36+
factory: () => faker.lorem.sentence({ min: 10, max: 25 }),
3737
},
3838

3939
url: {

storage/framework/orm/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
export * from './Subscriber.ts'
2-
3-
export * from './utils'

storage/framework/orm/src/utils.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)