Skip to content

Commit 29406ca

Browse files
committedFeb 5, 2025·
chore: wip
1 parent f567483 commit 29406ca

18 files changed

+216
-144
lines changed
 

‎storage/framework/core/orm/src/generate.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,30 @@ export async function generateModelString(
997997
return await instance.applyFind(id)
998998
}
999999
1000-
async first(): Promise<${modelName}Model | undefined> {
1001-
return await ${modelName}Model.first()
1002-
}
1003-
1004-
static async first(): Promise<${modelName}Model | undefined> {
1000+
async applyFirst(): Promise<${modelName}Model | undefined> {
10051001
const model = await DB.instance.selectFrom('${tableName}')
10061002
.selectAll()
10071003
.executeTakeFirst()
10081004
10091005
if (! model)
10101006
return undefined
10111007
1012-
const instance = new ${modelName}Model(null)
1013-
1014-
const result = await instance.mapWith(model)
1008+
const result = await this.mapWith(model)
10151009
10161010
const data = new ${modelName}Model(result as ${modelName}Type)
10171011
10181012
return data
10191013
}
1014+
1015+
async first(): Promise<${modelName}Model | undefined> {
1016+
return await this.first()
1017+
}
1018+
1019+
static async first(): Promise<${modelName}Model | undefined> {
1020+
const instance = new ${modelName}Model(null)
1021+
1022+
return await instance.first()
1023+
}
10201024
10211025
async firstOrFail(): Promise<${modelName}Model | undefined> {
10221026
return await ${modelName}Model.firstOrFail()

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -228,27 +228,31 @@ export class AccessTokenModel {
228228
return await instance.applyFind(id)
229229
}
230230

231-
async first(): Promise<AccessTokenModel | undefined> {
232-
return await AccessTokenModel.first()
233-
}
234-
235-
static async first(): Promise<AccessTokenModel | undefined> {
231+
async applyFirst(): Promise<AccessTokenModel | undefined> {
236232
const model = await DB.instance.selectFrom('personal_access_tokens')
237233
.selectAll()
238234
.executeTakeFirst()
239235

240236
if (!model)
241237
return undefined
242238

243-
const instance = new AccessTokenModel(null)
244-
245-
const result = await instance.mapWith(model)
239+
const result = await this.mapWith(model)
246240

247241
const data = new AccessTokenModel(result as AccessTokenType)
248242

249243
return data
250244
}
251245

246+
async first(): Promise<AccessTokenModel | undefined> {
247+
return await this.first()
248+
}
249+
250+
static async first(): Promise<AccessTokenModel | undefined> {
251+
const instance = new AccessTokenModel(null)
252+
253+
return await instance.first()
254+
}
255+
252256
async firstOrFail(): Promise<AccessTokenModel | undefined> {
253257
return await AccessTokenModel.firstOrFail()
254258
}

‎storage/framework/orm/src/models/Activity.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,31 @@ export class ActivityModel {
243243
return await instance.applyFind(id)
244244
}
245245

246-
async first(): Promise<ActivityModel | undefined> {
247-
return await ActivityModel.first()
248-
}
249-
250-
static async first(): Promise<ActivityModel | undefined> {
246+
async applyFirst(): Promise<ActivityModel | undefined> {
251247
const model = await DB.instance.selectFrom('activities')
252248
.selectAll()
253249
.executeTakeFirst()
254250

255251
if (!model)
256252
return undefined
257253

258-
const instance = new ActivityModel(null)
259-
260-
const result = await instance.mapWith(model)
254+
const result = await this.mapWith(model)
261255

262256
const data = new ActivityModel(result as ActivityType)
263257

264258
return data
265259
}
266260

261+
async first(): Promise<ActivityModel | undefined> {
262+
return await this.first()
263+
}
264+
265+
static async first(): Promise<ActivityModel | undefined> {
266+
const instance = new ActivityModel(null)
267+
268+
return await instance.first()
269+
}
270+
267271
async firstOrFail(): Promise<ActivityModel | undefined> {
268272
return await ActivityModel.firstOrFail()
269273
}

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,31 @@ export class DeploymentModel {
265265
return await instance.applyFind(id)
266266
}
267267

268-
async first(): Promise<DeploymentModel | undefined> {
269-
return await DeploymentModel.first()
270-
}
271-
272-
static async first(): Promise<DeploymentModel | undefined> {
268+
async applyFirst(): Promise<DeploymentModel | undefined> {
273269
const model = await DB.instance.selectFrom('deployments')
274270
.selectAll()
275271
.executeTakeFirst()
276272

277273
if (!model)
278274
return undefined
279275

280-
const instance = new DeploymentModel(null)
281-
282-
const result = await instance.mapWith(model)
276+
const result = await this.mapWith(model)
283277

284278
const data = new DeploymentModel(result as DeploymentType)
285279

286280
return data
287281
}
288282

283+
async first(): Promise<DeploymentModel | undefined> {
284+
return await this.first()
285+
}
286+
287+
static async first(): Promise<DeploymentModel | undefined> {
288+
const instance = new DeploymentModel(null)
289+
290+
return await instance.first()
291+
}
292+
289293
async firstOrFail(): Promise<DeploymentModel | undefined> {
290294
return await DeploymentModel.firstOrFail()
291295
}

‎storage/framework/orm/src/models/Error.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,31 @@ export class ErrorModel {
224224
return await instance.applyFind(id)
225225
}
226226

227-
async first(): Promise<ErrorModel | undefined> {
228-
return await ErrorModel.first()
229-
}
230-
231-
static async first(): Promise<ErrorModel | undefined> {
227+
async applyFirst(): Promise<ErrorModel | undefined> {
232228
const model = await DB.instance.selectFrom('errors')
233229
.selectAll()
234230
.executeTakeFirst()
235231

236232
if (!model)
237233
return undefined
238234

239-
const instance = new ErrorModel(null)
240-
241-
const result = await instance.mapWith(model)
235+
const result = await this.mapWith(model)
242236

243237
const data = new ErrorModel(result as ErrorType)
244238

245239
return data
246240
}
247241

242+
async first(): Promise<ErrorModel | undefined> {
243+
return await this.first()
244+
}
245+
246+
static async first(): Promise<ErrorModel | undefined> {
247+
const instance = new ErrorModel(null)
248+
249+
return await instance.first()
250+
}
251+
248252
async firstOrFail(): Promise<ErrorModel | undefined> {
249253
return await ErrorModel.firstOrFail()
250254
}

‎storage/framework/orm/src/models/FailedJob.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,31 @@ export class FailedJobModel {
224224
return await instance.applyFind(id)
225225
}
226226

227-
async first(): Promise<FailedJobModel | undefined> {
228-
return await FailedJobModel.first()
229-
}
230-
231-
static async first(): Promise<FailedJobModel | undefined> {
227+
async applyFirst(): Promise<FailedJobModel | undefined> {
232228
const model = await DB.instance.selectFrom('failed_jobs')
233229
.selectAll()
234230
.executeTakeFirst()
235231

236232
if (!model)
237233
return undefined
238234

239-
const instance = new FailedJobModel(null)
240-
241-
const result = await instance.mapWith(model)
235+
const result = await this.mapWith(model)
242236

243237
const data = new FailedJobModel(result as FailedJobType)
244238

245239
return data
246240
}
247241

242+
async first(): Promise<FailedJobModel | undefined> {
243+
return await this.first()
244+
}
245+
246+
static async first(): Promise<FailedJobModel | undefined> {
247+
const instance = new FailedJobModel(null)
248+
249+
return await instance.first()
250+
}
251+
248252
async firstOrFail(): Promise<FailedJobModel | undefined> {
249253
return await FailedJobModel.firstOrFail()
250254
}

‎storage/framework/orm/src/models/Job.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,31 @@ export class JobModel {
224224
return await instance.applyFind(id)
225225
}
226226

227-
async first(): Promise<JobModel | undefined> {
228-
return await JobModel.first()
229-
}
230-
231-
static async first(): Promise<JobModel | undefined> {
227+
async applyFirst(): Promise<JobModel | undefined> {
232228
const model = await DB.instance.selectFrom('jobs')
233229
.selectAll()
234230
.executeTakeFirst()
235231

236232
if (!model)
237233
return undefined
238234

239-
const instance = new JobModel(null)
240-
241-
const result = await instance.mapWith(model)
235+
const result = await this.mapWith(model)
242236

243237
const data = new JobModel(result as JobType)
244238

245239
return data
246240
}
247241

242+
async first(): Promise<JobModel | undefined> {
243+
return await this.first()
244+
}
245+
246+
static async first(): Promise<JobModel | undefined> {
247+
const instance = new JobModel(null)
248+
249+
return await instance.first()
250+
}
251+
248252
async firstOrFail(): Promise<JobModel | undefined> {
249253
return await JobModel.firstOrFail()
250254
}

‎storage/framework/orm/src/models/PaymentMethod.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,31 @@ export class PaymentMethodModel {
274274
return await instance.applyFind(id)
275275
}
276276

277-
async first(): Promise<PaymentMethodModel | undefined> {
278-
return await PaymentMethodModel.first()
279-
}
280-
281-
static async first(): Promise<PaymentMethodModel | undefined> {
277+
async applyFirst(): Promise<PaymentMethodModel | undefined> {
282278
const model = await DB.instance.selectFrom('payment_methods')
283279
.selectAll()
284280
.executeTakeFirst()
285281

286282
if (!model)
287283
return undefined
288284

289-
const instance = new PaymentMethodModel(null)
290-
291-
const result = await instance.mapWith(model)
285+
const result = await this.mapWith(model)
292286

293287
const data = new PaymentMethodModel(result as PaymentMethodType)
294288

295289
return data
296290
}
297291

292+
async first(): Promise<PaymentMethodModel | undefined> {
293+
return await this.first()
294+
}
295+
296+
static async first(): Promise<PaymentMethodModel | undefined> {
297+
const instance = new PaymentMethodModel(null)
298+
299+
return await instance.first()
300+
}
301+
298302
async firstOrFail(): Promise<PaymentMethodModel | undefined> {
299303
return await PaymentMethodModel.firstOrFail()
300304
}

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -210,27 +210,31 @@ export class PostModel {
210210
return await instance.applyFind(id)
211211
}
212212

213-
async first(): Promise<PostModel | undefined> {
214-
return await PostModel.first()
215-
}
216-
217-
static async first(): Promise<PostModel | undefined> {
213+
async applyFirst(): Promise<PostModel | undefined> {
218214
const model = await DB.instance.selectFrom('posts')
219215
.selectAll()
220216
.executeTakeFirst()
221217

222218
if (!model)
223219
return undefined
224220

225-
const instance = new PostModel(null)
226-
227-
const result = await instance.mapWith(model)
221+
const result = await this.mapWith(model)
228222

229223
const data = new PostModel(result as PostType)
230224

231225
return data
232226
}
233227

228+
async first(): Promise<PostModel | undefined> {
229+
return await this.first()
230+
}
231+
232+
static async first(): Promise<PostModel | undefined> {
233+
const instance = new PostModel(null)
234+
235+
return await instance.first()
236+
}
237+
234238
async firstOrFail(): Promise<PostModel | undefined> {
235239
return await PostModel.firstOrFail()
236240
}

‎storage/framework/orm/src/models/Product.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,31 @@ export class ProductModel {
252252
return await instance.applyFind(id)
253253
}
254254

255-
async first(): Promise<ProductModel | undefined> {
256-
return await ProductModel.first()
257-
}
258-
259-
static async first(): Promise<ProductModel | undefined> {
255+
async applyFirst(): Promise<ProductModel | undefined> {
260256
const model = await DB.instance.selectFrom('products')
261257
.selectAll()
262258
.executeTakeFirst()
263259

264260
if (!model)
265261
return undefined
266262

267-
const instance = new ProductModel(null)
268-
269-
const result = await instance.mapWith(model)
263+
const result = await this.mapWith(model)
270264

271265
const data = new ProductModel(result as ProductType)
272266

273267
return data
274268
}
275269

270+
async first(): Promise<ProductModel | undefined> {
271+
return await this.first()
272+
}
273+
274+
static async first(): Promise<ProductModel | undefined> {
275+
const instance = new ProductModel(null)
276+
277+
return await instance.first()
278+
}
279+
276280
async firstOrFail(): Promise<ProductModel | undefined> {
277281
return await ProductModel.firstOrFail()
278282
}

0 commit comments

Comments
 (0)
Please sign in to comment.