Skip to content

Commit 30b4160

Browse files
chore: wip
1 parent e9a952d commit 30b4160

File tree

10 files changed

+63
-60
lines changed

10 files changed

+63
-60
lines changed

storage/framework/core/actions/src/orm/generate-model.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { log } from '@stacksjs/logging'
22
import { getModelName, getTableName } from '@stacksjs/orm'
33
import { path } from '@stacksjs/path'
44
import { fs, glob } from '@stacksjs/storage'
5-
import { camelCase, pascalCase } from '@stacksjs/strings'
5+
import { camelCase, pascalCase, plural } from '@stacksjs/strings'
66
import type { Model, RelationConfig } from '@stacksjs/types'
77
import { isString } from '@stacksjs/validation'
88
export interface FieldArrayElement {
@@ -739,7 +739,7 @@ async function generateModelString(
739739

740740
if (relationType === 'belongsType' && relationCount === 'many') {
741741
const pivotTable = pivotTableRelation || tableRelation
742-
const relationName = relation.relationName || formattedModelName + capitalizeTableRelation
742+
const relationName = relation.relationName || formattedModelName + plural(pascalCase(modelRelation))
743743

744744
relationMethods += `
745745
async ${relationName}() {
@@ -902,7 +902,7 @@ async function generateModelString(
902902
}
903903
904904
// Method to get a ${modelName} by criteria
905-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<${modelName}Model[]> {
905+
static async fetch(criteria: Partial<${modelName}Type>, options: QueryOptions = {}): Promise<${modelName}Model[]> {
906906
let query = db.selectFrom('${tableName}')
907907
908908
// Apply sorting from options
@@ -966,7 +966,7 @@ async function generateModelString(
966966
}
967967
968968
// Method to create a new ${formattedModelName}
969-
static async create(newAccessToken: NewAccessToken): Promise<${modelName}Model> {
969+
static async create(${tableName}: New${modelName}): Promise<${modelName}Model> {
970970
const result = await db.insertInto('${tableName}')
971971
.values(new${modelName})
972972
.executeTakeFirstOrThrow()
@@ -1035,13 +1035,13 @@ async function generateModelString(
10351035
return new ${modelName}Model(model)
10361036
}
10371037
1038-
static async first(): Promise<AccessTokenType | undefined> {
1038+
static async first(): Promise<${modelName}Type | undefined> {
10391039
return await db.selectFrom('${tableName}')
10401040
.selectAll()
10411041
.executeTakeFirst()
10421042
}
10431043
1044-
async last(): Promise<${modelName}Type> {
1044+
async last(): Promise<${modelName}Type | un> {
10451045
return await db.selectFrom('${tableName}')
10461046
.selectAll()
10471047
.orderBy('id', 'desc')
@@ -1090,10 +1090,10 @@ async function generateModelString(
10901090
return this
10911091
}
10921092
1093-
// Method to update the accesstoken instance
1093+
// Method to update the ${tableName} instance
10941094
async update(${formattedModelName}: ${modelName}Update): Promise<${modelName}Model | null> {
10951095
if (this.id === undefined)
1096-
throw new Error('AccessToken ID is undefined')
1096+
throw new Error('${modelName} ID is undefined')
10971097
10981098
const updatedModel = await db.updateTable('${tableName}')
10991099
.set(${formattedModelName})

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class AccessTokenModel {
192192
}
193193

194194
// Method to create a new accesstoken
195-
static async create(newAccessToken: NewAccessToken): Promise<AccessTokenModel> {
195+
static async create(personal_access_tokens: NewAccessToken): Promise<AccessTokenModel> {
196196
const result = await db.insertInto('personal_access_tokens').values(newAccessToken).executeTakeFirstOrThrow()
197197

198198
return (await find(Number(result.insertId))) as AccessTokenModel
@@ -261,7 +261,7 @@ export class AccessTokenModel {
261261
return await db.selectFrom('personal_access_tokens').selectAll().executeTakeFirst()
262262
}
263263

264-
async last(): Promise<AccessTokenType> {
264+
async last(): Promise<AccessTokenType | un> {
265265
return await db.selectFrom('personal_access_tokens').selectAll().orderBy('id', 'desc').executeTakeFirst()
266266
}
267267

@@ -307,7 +307,7 @@ export class AccessTokenModel {
307307
return this
308308
}
309309

310-
// Method to update the accesstoken instance
310+
// Method to update the personal_access_tokens instance
311311
async update(accesstoken: AccessTokenUpdate): Promise<AccessTokenModel | null> {
312312
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
313313

storage/framework/orm/src/models/Deployment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class DeploymentModel {
138138
}
139139

140140
// Method to get a Deployment by criteria
141-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<DeploymentModel[]> {
141+
static async fetch(criteria: Partial<DeploymentType>, options: QueryOptions = {}): Promise<DeploymentModel[]> {
142142
let query = db.selectFrom('deployments')
143143

144144
// Apply sorting from options
@@ -200,7 +200,7 @@ export class DeploymentModel {
200200
}
201201

202202
// Method to create a new deployment
203-
static async create(newAccessToken: NewAccessToken): Promise<DeploymentModel> {
203+
static async create(deployments: NewDeployment): Promise<DeploymentModel> {
204204
const result = await db.insertInto('deployments').values(newDeployment).executeTakeFirstOrThrow()
205205

206206
return (await find(Number(result.insertId))) as DeploymentModel
@@ -265,11 +265,11 @@ export class DeploymentModel {
265265
return new DeploymentModel(model)
266266
}
267267

268-
static async first(): Promise<AccessTokenType | undefined> {
268+
static async first(): Promise<DeploymentType | undefined> {
269269
return await db.selectFrom('deployments').selectAll().executeTakeFirst()
270270
}
271271

272-
async last(): Promise<DeploymentType> {
272+
async last(): Promise<DeploymentType | un> {
273273
return await db.selectFrom('deployments').selectAll().orderBy('id', 'desc').executeTakeFirst()
274274
}
275275

@@ -315,9 +315,9 @@ export class DeploymentModel {
315315
return this
316316
}
317317

318-
// Method to update the accesstoken instance
318+
// Method to update the deployments instance
319319
async update(deployment: DeploymentUpdate): Promise<DeploymentModel | null> {
320-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
320+
if (this.id === undefined) throw new Error('Deployment ID is undefined')
321321

322322
const updatedModel = await db
323323
.updateTable('deployments')

storage/framework/orm/src/models/Post.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class PostModel {
123123
}
124124

125125
// Method to get a Post by criteria
126-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<PostModel[]> {
126+
static async fetch(criteria: Partial<PostType>, options: QueryOptions = {}): Promise<PostModel[]> {
127127
let query = db.selectFrom('posts')
128128

129129
// Apply sorting from options
@@ -185,7 +185,7 @@ export class PostModel {
185185
}
186186

187187
// Method to create a new post
188-
static async create(newAccessToken: NewAccessToken): Promise<PostModel> {
188+
static async create(posts: NewPost): Promise<PostModel> {
189189
const result = await db.insertInto('posts').values(newPost).executeTakeFirstOrThrow()
190190

191191
return (await find(Number(result.insertId))) as PostModel
@@ -250,11 +250,11 @@ export class PostModel {
250250
return new PostModel(model)
251251
}
252252

253-
static async first(): Promise<AccessTokenType | undefined> {
253+
static async first(): Promise<PostType | undefined> {
254254
return await db.selectFrom('posts').selectAll().executeTakeFirst()
255255
}
256256

257-
async last(): Promise<PostType> {
257+
async last(): Promise<PostType | un> {
258258
return await db.selectFrom('posts').selectAll().orderBy('id', 'desc').executeTakeFirst()
259259
}
260260

@@ -300,9 +300,9 @@ export class PostModel {
300300
return this
301301
}
302302

303-
// Method to update the accesstoken instance
303+
// Method to update the posts instance
304304
async update(post: PostUpdate): Promise<PostModel | null> {
305-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
305+
if (this.id === undefined) throw new Error('Post ID is undefined')
306306

307307
const updatedModel = await db.updateTable('posts').set(post).where('id', '=', this.id).executeTakeFirst()
308308

storage/framework/orm/src/models/Project.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class ProjectModel {
125125
}
126126

127127
// Method to get a Project by criteria
128-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<ProjectModel[]> {
128+
static async fetch(criteria: Partial<ProjectType>, options: QueryOptions = {}): Promise<ProjectModel[]> {
129129
let query = db.selectFrom('projects')
130130

131131
// Apply sorting from options
@@ -187,7 +187,7 @@ export class ProjectModel {
187187
}
188188

189189
// Method to create a new project
190-
static async create(newAccessToken: NewAccessToken): Promise<ProjectModel> {
190+
static async create(projects: NewProject): Promise<ProjectModel> {
191191
const result = await db.insertInto('projects').values(newProject).executeTakeFirstOrThrow()
192192

193193
return (await find(Number(result.insertId))) as ProjectModel
@@ -252,11 +252,11 @@ export class ProjectModel {
252252
return new ProjectModel(model)
253253
}
254254

255-
static async first(): Promise<AccessTokenType | undefined> {
255+
static async first(): Promise<ProjectType | undefined> {
256256
return await db.selectFrom('projects').selectAll().executeTakeFirst()
257257
}
258258

259-
async last(): Promise<ProjectType> {
259+
async last(): Promise<ProjectType | un> {
260260
return await db.selectFrom('projects').selectAll().orderBy('id', 'desc').executeTakeFirst()
261261
}
262262

@@ -302,9 +302,9 @@ export class ProjectModel {
302302
return this
303303
}
304304

305-
// Method to update the accesstoken instance
305+
// Method to update the projects instance
306306
async update(project: ProjectUpdate): Promise<ProjectModel | null> {
307-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
307+
if (this.id === undefined) throw new Error('Project ID is undefined')
308308

309309
const updatedModel = await db.updateTable('projects').set(project).where('id', '=', this.id).executeTakeFirst()
310310

storage/framework/orm/src/models/Release.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class ReleaseModel {
116116
}
117117

118118
// Method to get a Release by criteria
119-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<ReleaseModel[]> {
119+
static async fetch(criteria: Partial<ReleaseType>, options: QueryOptions = {}): Promise<ReleaseModel[]> {
120120
let query = db.selectFrom('releases')
121121

122122
// Apply sorting from options
@@ -178,7 +178,7 @@ export class ReleaseModel {
178178
}
179179

180180
// Method to create a new release
181-
static async create(newAccessToken: NewAccessToken): Promise<ReleaseModel> {
181+
static async create(releases: NewRelease): Promise<ReleaseModel> {
182182
const result = await db.insertInto('releases').values(newRelease).executeTakeFirstOrThrow()
183183

184184
return (await find(Number(result.insertId))) as ReleaseModel
@@ -243,11 +243,11 @@ export class ReleaseModel {
243243
return new ReleaseModel(model)
244244
}
245245

246-
static async first(): Promise<AccessTokenType | undefined> {
246+
static async first(): Promise<ReleaseType | undefined> {
247247
return await db.selectFrom('releases').selectAll().executeTakeFirst()
248248
}
249249

250-
async last(): Promise<ReleaseType> {
250+
async last(): Promise<ReleaseType | un> {
251251
return await db.selectFrom('releases').selectAll().orderBy('id', 'desc').executeTakeFirst()
252252
}
253253

@@ -293,9 +293,9 @@ export class ReleaseModel {
293293
return this
294294
}
295295

296-
// Method to update the accesstoken instance
296+
// Method to update the releases instance
297297
async update(release: ReleaseUpdate): Promise<ReleaseModel | null> {
298-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
298+
if (this.id === undefined) throw new Error('Release ID is undefined')
299299

300300
const updatedModel = await db.updateTable('releases').set(release).where('id', '=', this.id).executeTakeFirst()
301301

storage/framework/orm/src/models/Subscriber.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class SubscriberModel {
119119
}
120120

121121
// Method to get a Subscriber by criteria
122-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<SubscriberModel[]> {
122+
static async fetch(criteria: Partial<SubscriberType>, options: QueryOptions = {}): Promise<SubscriberModel[]> {
123123
let query = db.selectFrom('subscribers')
124124

125125
// Apply sorting from options
@@ -181,7 +181,7 @@ export class SubscriberModel {
181181
}
182182

183183
// Method to create a new subscriber
184-
static async create(newAccessToken: NewAccessToken): Promise<SubscriberModel> {
184+
static async create(subscribers: NewSubscriber): Promise<SubscriberModel> {
185185
const result = await db.insertInto('subscribers').values(newSubscriber).executeTakeFirstOrThrow()
186186

187187
return (await find(Number(result.insertId))) as SubscriberModel
@@ -246,11 +246,11 @@ export class SubscriberModel {
246246
return new SubscriberModel(model)
247247
}
248248

249-
static async first(): Promise<AccessTokenType | undefined> {
249+
static async first(): Promise<SubscriberType | undefined> {
250250
return await db.selectFrom('subscribers').selectAll().executeTakeFirst()
251251
}
252252

253-
async last(): Promise<SubscriberType> {
253+
async last(): Promise<SubscriberType | un> {
254254
return await db.selectFrom('subscribers').selectAll().orderBy('id', 'desc').executeTakeFirst()
255255
}
256256

@@ -296,9 +296,9 @@ export class SubscriberModel {
296296
return this
297297
}
298298

299-
// Method to update the accesstoken instance
299+
// Method to update the subscribers instance
300300
async update(subscriber: SubscriberUpdate): Promise<SubscriberModel | null> {
301-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
301+
if (this.id === undefined) throw new Error('Subscriber ID is undefined')
302302

303303
const updatedModel = await db
304304
.updateTable('subscribers')

storage/framework/orm/src/models/SubscriberEmail.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ export class SubscriberEmailModel {
116116
}
117117

118118
// Method to get a SubscriberEmail by criteria
119-
static async fetch(criteria: Partial<AccessTokenType>, options: QueryOptions = {}): Promise<SubscriberEmailModel[]> {
119+
static async fetch(
120+
criteria: Partial<SubscriberEmailType>,
121+
options: QueryOptions = {},
122+
): Promise<SubscriberEmailModel[]> {
120123
let query = db.selectFrom('subscriber_emails')
121124

122125
// Apply sorting from options
@@ -178,7 +181,7 @@ export class SubscriberEmailModel {
178181
}
179182

180183
// Method to create a new subscriberemail
181-
static async create(newAccessToken: NewAccessToken): Promise<SubscriberEmailModel> {
184+
static async create(subscriber_emails: NewSubscriberEmail): Promise<SubscriberEmailModel> {
182185
const result = await db.insertInto('subscriber_emails').values(newSubscriberEmail).executeTakeFirstOrThrow()
183186

184187
return (await find(Number(result.insertId))) as SubscriberEmailModel
@@ -243,11 +246,11 @@ export class SubscriberEmailModel {
243246
return new SubscriberEmailModel(model)
244247
}
245248

246-
static async first(): Promise<AccessTokenType | undefined> {
249+
static async first(): Promise<SubscriberEmailType | undefined> {
247250
return await db.selectFrom('subscriber_emails').selectAll().executeTakeFirst()
248251
}
249252

250-
async last(): Promise<SubscriberEmailType> {
253+
async last(): Promise<SubscriberEmailType | un> {
251254
return await db.selectFrom('subscriber_emails').selectAll().orderBy('id', 'desc').executeTakeFirst()
252255
}
253256

@@ -293,9 +296,9 @@ export class SubscriberEmailModel {
293296
return this
294297
}
295298

296-
// Method to update the accesstoken instance
299+
// Method to update the subscriber_emails instance
297300
async update(subscriberemail: SubscriberEmailUpdate): Promise<SubscriberEmailModel | null> {
298-
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
301+
if (this.id === undefined) throw new Error('SubscriberEmail ID is undefined')
299302

300303
const updatedModel = await db
301304
.updateTable('subscriber_emails')

0 commit comments

Comments
 (0)