Skip to content

Commit 3ecf02b

Browse files
committed
chore: wip
1 parent de67776 commit 3ecf02b

File tree

4 files changed

+77
-73
lines changed

4 files changed

+77
-73
lines changed

.stacks/core/actions/src/build/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { frameworkPath } from '@stacksjs/path'
22
import { runCommands } from '@stacksjs/cli'
33

44
await runCommands([
5-
'pnpm --filter "./core/*" --filter "!./core/x-ray" --filter "!./core/buddy" build', // command to build the core packages, excluding the config & x-ray package
5+
'pnpm -r --filter "./core/*" --filter "!./core/x-ray" --filter "!./core/buddy" build', // command to build the core packages, excluding the config & x-ray package
66
// 'pnpm --filter "./core/*" --filter "!./core/x-ray" --filter "!./core/buddy" build', // command to build the core packages, excluding the config & x-ray package
77
// 'pnpm --filter ./core/config build', // command to build the config package
88
], { verbose: true, cwd: frameworkPath(), shell: true })

.stacks/core/database/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
"@stacksjs/strings": "workspace:*",
5050
"@stacksjs/utils": "workspace:*"
5151
},
52+
"dependencies": {
53+
"@stacksjs/config": "workspace:*"
54+
},
5255
"devDependencies": {
5356
"@stacksjs/development": "workspace:*"
5457
}
Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,79 @@
1-
import { MysqlDialect, QueryBuilder, createPool } from '@stacksjs/query-builder'
2-
import { filesystem } from '@stacksjs/storage'
3-
import type { Model } from '@stacksjs/types'
4-
import { projectPath } from '@stacksjs/path'
5-
import { database as config } from '@stacksjs/config'
6-
7-
const { fs } = filesystem
8-
9-
function readModels(folderPath: string): Promise<Model[]> {
10-
return new Promise((resolve, reject) => {
11-
const models: Model[] = []
12-
13-
fs.readdir(folderPath, (err, files) => {
14-
if (err)
15-
reject(err)
16-
17-
const promises = files
18-
.filter(file => file.endsWith('.ts'))
19-
.map((file) => {
20-
const filePath = `${folderPath}/${file}`
21-
22-
return import(filePath).then((data) => {
23-
models.push({
24-
name: data.default.name,
25-
fields: data.default.fields,
26-
useSeed: data.default.useSeed,
27-
})
28-
})
29-
})
30-
31-
Promise.all(promises)
32-
.then(() => resolve(models))
33-
.catch(err => reject(err))
34-
})
35-
})
36-
}
1+
// import { MysqlDialect, QueryBuilder, createPool } from '@stacksjs/query-builder'
2+
// import { filesystem } from '@stacksjs/storage'
3+
// import type { Model } from '@stacksjs/types'
4+
// import { projectPath } from '@stacksjs/path'
5+
// import { database as config } from '@stacksjs/config'
6+
7+
// const { fs } = filesystem
8+
9+
// function readModels(folderPath: string): Promise<Model[]> {
10+
// return new Promise((resolve, reject) => {
11+
// const models: Model[] = []
12+
13+
// fs.readdir(folderPath, (err, files) => {
14+
// if (err)
15+
// reject(err)
16+
17+
// const promises = files
18+
// .filter(file => file.endsWith('.ts'))
19+
// .map((file) => {
20+
// const filePath = `${folderPath}/${file}`
21+
22+
// return import(filePath).then((data) => {
23+
// models.push({
24+
// name: data.default.name,
25+
// fields: data.default.fields,
26+
// useSeed: data.default.useSeed,
27+
// })
28+
// })
29+
// })
30+
31+
// Promise.all(promises)
32+
// .then(() => resolve(models))
33+
// .catch(err => reject(err))
34+
// })
35+
// })
36+
// }
3737

3838
async function seed() {
39-
const db = new QueryBuilder({
40-
dialect: new MysqlDialect({
41-
pool: createPool({
42-
database: config.database,
43-
host: config.host,
44-
password: config.password,
45-
user: config.username,
46-
}),
47-
}),
48-
})
49-
50-
const models = await readModels(projectPath('app/models'))
51-
52-
const queries = models.flatMap((model) => {
53-
const { seedable, fields } = model
54-
55-
if (!seedable)
56-
return []
57-
58-
const count = typeof seedable === 'boolean' ? 10 : seedable.count
59-
60-
const records: Record<string, any>[] = []
61-
for (let i = 0; i < count; i++) {
62-
const record: Record<string, any> = {}
63-
Object.entries(fields).forEach(([name, field]) => {
64-
if (field.factory)
65-
record[name] = field.factory()
66-
})
67-
records.push(record)
68-
}
69-
70-
return model
71-
// return db.insertInto('User').values(records).build(sql`RETURNING *`)
72-
})
39+
// const db = new QueryBuilder({
40+
// dialect: new MysqlDialect({
41+
// pool: createPool({
42+
// database: config.database,
43+
// host: config.host,
44+
// password: config.password,
45+
// user: config.username,
46+
// }),
47+
// }),
48+
// })
49+
50+
// const models = await readModels(projectPath('app/models'))
51+
52+
// const queries = models.flatMap((model) => {
53+
// const { seedable, fields } = model
54+
55+
// if (!seedable)
56+
// return []
57+
58+
// const count = typeof seedable === 'boolean' ? 10 : seedable.count
59+
60+
// const records: Record<string, any>[] = []
61+
// for (let i = 0; i < count; i++) {
62+
// const record: Record<string, any> = {}
63+
// Object.entries(fields).forEach(([name, field]) => {
64+
// if (field.factory)
65+
// record[name] = field.factory()
66+
// })
67+
// records.push(record)
68+
// }
69+
70+
// return model
71+
// // return db.insertInto('User').values(records).build(sql`RETURNING *`)
72+
// })
7373

7474
// const { rows } = await db.transaction().execute()
7575

7676
// return rows
7777
}
7878

7979
export { seed }
80-
81-
export {}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)