File tree Expand file tree Collapse file tree 4 files changed +37
-26
lines changed Expand file tree Collapse file tree 4 files changed +37
-26
lines changed Original file line number Diff line number Diff line change 1
1
import { log } from '@stacksjs/logging'
2
- import { migrations } from '@stacksjs/database'
2
+ import { readModelsFromFolder } from '@stacksjs/database'
3
3
import { Action , NpmScript } from '@stacksjs/types'
4
4
import type { GeneratorOptions } from '@stacksjs/types'
5
5
import { runNpmScript } from '@stacksjs/utils'
@@ -120,5 +120,6 @@ export async function types(options?: GeneratorOptions) {
120
120
}
121
121
122
122
export async function models ( options ?: any ) {
123
- log . success ( migrations )
123
+ const test = await readModelsFromFolder ( `${ projectPath ( ) } /config/models` )
124
+ console . log ( test )
124
125
}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ interface Model {
16
16
}
17
17
18
18
interface ModelData {
19
- [ key : string ] : any ;
19
+ [ key : string ] : any
20
20
}
21
21
22
22
function generatePrismaSchema ( models : Model [ ] , path : string ) : void {
@@ -69,24 +69,25 @@ generator client {
69
69
}
70
70
71
71
function readModelsFromFolder ( folderPath : string ) : ModelData [ ] {
72
- const models : ModelData [ ] = [ ] ;
72
+ const models : ModelData [ ] = [ ]
73
73
74
74
fs . readdirSync ( folderPath ) . forEach ( ( file ) => {
75
75
if ( file . endsWith ( '.ts' ) ) {
76
- const filePath = `${ folderPath } /${ file } ` ;
77
- const fileContents = fs . readFileSync ( filePath , 'utf-8' ) ;
76
+ const filePath = `${ folderPath } /${ file } `
77
+ const fileContents = fs . readFileSync ( filePath , 'utf-8' )
78
78
79
- const regex = / r e t u r n \s * { ( [ ^ } ] * ) } / m;
80
- const match = fileContents . match ( regex ) ;
79
+ const regex = / r e t u r n \s * { ( [ ^ } ] * ) } / m
80
+ const match = fileContents . match ( regex )
81
81
82
82
if ( match ) {
83
- const modelData = eval ( `({${ match [ 1 ] } })` ) ;
84
- models . push ( modelData ) ;
83
+ console . log ( match [ 0 ] ) ;
84
+ const modelData = eval ( `({${ match [ 1 ] } })` )
85
+ models . push ( modelData )
85
86
}
86
87
}
87
- } ) ;
88
+ } )
88
89
89
- return models ;
90
+ return models
90
91
}
91
92
92
93
export {
Original file line number Diff line number Diff line change 1
- import { PrismaClient } from '@prisma/client'
1
+ // import { PrismaClient } from '@prisma/client'
2
2
import type { SeedData } from '@stacksjs/types'
3
3
4
4
async function seed ( modelName : string , data : SeedData [ ] ) : Promise < void > {
5
- const prisma = new PrismaClient ( )
5
+ // const prisma = new PrismaClient()
6
6
7
- try {
8
- const model = prisma [ modelName ]
9
- const seedPromises = data . map ( item => model . create ( { data : item } ) )
10
- await Promise . all ( seedPromises )
11
- console . log ( `Seeding successful for model "${ modelName } "` )
12
- }
13
- catch ( error ) {
14
- console . error ( `Error seeding model "${ modelName } ": ${ error . message } ` )
15
- }
16
- finally {
17
- await prisma . $disconnect ( )
18
- }
7
+ // try {
8
+ // const model = prisma[modelName]
9
+ // const seedPromises = data.map(item => model.create({ data: item }))
10
+ // await Promise.all(seedPromises)
11
+ // console.log(`Seeding successful for model "${modelName}"`)
12
+ // }
13
+ // catch (error) {
14
+ // console.error(`Error seeding model "${modelName}": ${error.message}`)
15
+ // }
16
+ // finally {
17
+ // await prisma.$disconnect()
18
+ // }
19
+ console . log ( 'test' )
19
20
}
20
21
21
22
export { seed }
Original file line number Diff line number Diff line change
1
+ export function getModelData ( ) {
2
+ return {
3
+ fields : [
4
+ { name : "id" , type : "string" } ,
5
+ { name : "name" , type : "string" }
6
+ ]
7
+ } ;
8
+ }
You can’t perform that action at this time.
0 commit comments