Skip to content

Commit 686ee47

Browse files
chore: wip
1 parent 32e34bf commit 686ee47

File tree

18 files changed

+110
-363
lines changed

18 files changed

+110
-363
lines changed

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,8 @@ export async function generateModelString(
11951195
.select(sql\`SUM(\${sql.raw(field as string)})\`)
11961196
.executeTakeFirst()
11971197
}
1198-
1199-
async get(): Promise<${modelName}Model[]> {
1198+
1199+
async applyGet(): Promise<${modelName}Model[]> {
12001200
let models
12011201
12021202
if (this.hasSelect) {
@@ -1216,30 +1216,14 @@ export async function generateModelString(
12161216
return data
12171217
}
12181218
1219+
async get(): Promise<${modelName}Model[]> {
1220+
return await this.applyGet()
1221+
}
1222+
12191223
static async get(): Promise<${modelName}Model[]> {
12201224
const instance = new ${modelName}Model(null)
1221-
1222-
let models
1223-
1224-
if (instance.hasSelect) {
1225-
${instanceSoftDeleteStatementsSelectFrom}
1226-
1227-
models = await instance.selectFromQuery.execute()
1228-
} else {
1229-
${instanceSoftDeleteStatementsSelectFrom}
1230-
1231-
models = await instance.selectFromQuery.selectAll().execute()
1232-
}
1233-
1234-
const data = await Promise.all(models.map(async (model: ${modelName}Model) => {
1235-
const instance = new ${modelName}Model(model)
1236-
1237-
const results = await instance.mapWith(model)
1238-
1239-
return new ${modelName}Model(results)
1240-
}))
1241-
1242-
return data
1225+
1226+
return await instance.applyGet()
12431227
}
12441228
12451229
has(relation: string): ${modelName}Model {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export class AccessTokenModel {
423423
.executeTakeFirst()
424424
}
425425

426-
async get(): Promise<AccessTokenModel[]> {
426+
async applyGet(): Promise<AccessTokenModel[]> {
427427
let models
428428

429429
if (this.hasSelect) {
@@ -444,27 +444,14 @@ export class AccessTokenModel {
444444
return data
445445
}
446446

447+
async get(): Promise<AccessTokenModel[]> {
448+
return await this.applyGet()
449+
}
450+
447451
static async get(): Promise<AccessTokenModel[]> {
448452
const instance = new AccessTokenModel(null)
449453

450-
let models
451-
452-
if (instance.hasSelect) {
453-
models = await instance.selectFromQuery.execute()
454-
}
455-
else {
456-
models = await instance.selectFromQuery.selectAll().execute()
457-
}
458-
459-
const data = await Promise.all(models.map(async (model: AccessTokenModel) => {
460-
const instance = new AccessTokenModel(model)
461-
462-
const results = await instance.mapWith(model)
463-
464-
return new AccessTokenModel(results)
465-
}))
466-
467-
return data
454+
return await instance.applyGet()
468455
}
469456

470457
has(relation: string): AccessTokenModel {

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export class ActivityModel {
442442
.executeTakeFirst()
443443
}
444444

445-
async get(): Promise<ActivityModel[]> {
445+
async applyGet(): Promise<ActivityModel[]> {
446446
let models
447447

448448
if (this.hasSelect) {
@@ -463,35 +463,14 @@ export class ActivityModel {
463463
return data
464464
}
465465

466+
async get(): Promise<ActivityModel[]> {
467+
return await this.applyGet()
468+
}
469+
466470
static async get(): Promise<ActivityModel[]> {
467471
const instance = new ActivityModel(null)
468472

469-
let models
470-
471-
if (instance.hasSelect) {
472-
if (instance.softDeletes) {
473-
instance.selectFromQuery = instance.selectFromQuery.where('deleted_at', 'is', null)
474-
}
475-
476-
models = await instance.selectFromQuery.execute()
477-
}
478-
else {
479-
if (instance.softDeletes) {
480-
instance.selectFromQuery = instance.selectFromQuery.where('deleted_at', 'is', null)
481-
}
482-
483-
models = await instance.selectFromQuery.selectAll().execute()
484-
}
485-
486-
const data = await Promise.all(models.map(async (model: ActivityModel) => {
487-
const instance = new ActivityModel(model)
488-
489-
const results = await instance.mapWith(model)
490-
491-
return new ActivityModel(results)
492-
}))
493-
494-
return data
473+
return await instance.applyGet()
495474
}
496475

497476
has(relation: string): ActivityModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export class DeploymentModel {
460460
.executeTakeFirst()
461461
}
462462

463-
async get(): Promise<DeploymentModel[]> {
463+
async applyGet(): Promise<DeploymentModel[]> {
464464
let models
465465

466466
if (this.hasSelect) {
@@ -481,27 +481,14 @@ export class DeploymentModel {
481481
return data
482482
}
483483

484+
async get(): Promise<DeploymentModel[]> {
485+
return await this.applyGet()
486+
}
487+
484488
static async get(): Promise<DeploymentModel[]> {
485489
const instance = new DeploymentModel(null)
486490

487-
let models
488-
489-
if (instance.hasSelect) {
490-
models = await instance.selectFromQuery.execute()
491-
}
492-
else {
493-
models = await instance.selectFromQuery.selectAll().execute()
494-
}
495-
496-
const data = await Promise.all(models.map(async (model: DeploymentModel) => {
497-
const instance = new DeploymentModel(model)
498-
499-
const results = await instance.mapWith(model)
500-
501-
return new DeploymentModel(results)
502-
}))
503-
504-
return data
491+
return await instance.applyGet()
505492
}
506493

507494
has(relation: string): DeploymentModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class ErrorModel {
415415
.executeTakeFirst()
416416
}
417417

418-
async get(): Promise<ErrorModel[]> {
418+
async applyGet(): Promise<ErrorModel[]> {
419419
let models
420420

421421
if (this.hasSelect) {
@@ -436,27 +436,14 @@ export class ErrorModel {
436436
return data
437437
}
438438

439+
async get(): Promise<ErrorModel[]> {
440+
return await this.applyGet()
441+
}
442+
439443
static async get(): Promise<ErrorModel[]> {
440444
const instance = new ErrorModel(null)
441445

442-
let models
443-
444-
if (instance.hasSelect) {
445-
models = await instance.selectFromQuery.execute()
446-
}
447-
else {
448-
models = await instance.selectFromQuery.selectAll().execute()
449-
}
450-
451-
const data = await Promise.all(models.map(async (model: ErrorModel) => {
452-
const instance = new ErrorModel(model)
453-
454-
const results = await instance.mapWith(model)
455-
456-
return new ErrorModel(results)
457-
}))
458-
459-
return data
446+
return await instance.applyGet()
460447
}
461448

462449
has(relation: string): ErrorModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class FailedJobModel {
415415
.executeTakeFirst()
416416
}
417417

418-
async get(): Promise<FailedJobModel[]> {
418+
async applyGet(): Promise<FailedJobModel[]> {
419419
let models
420420

421421
if (this.hasSelect) {
@@ -436,27 +436,14 @@ export class FailedJobModel {
436436
return data
437437
}
438438

439+
async get(): Promise<FailedJobModel[]> {
440+
return await this.applyGet()
441+
}
442+
439443
static async get(): Promise<FailedJobModel[]> {
440444
const instance = new FailedJobModel(null)
441445

442-
let models
443-
444-
if (instance.hasSelect) {
445-
models = await instance.selectFromQuery.execute()
446-
}
447-
else {
448-
models = await instance.selectFromQuery.selectAll().execute()
449-
}
450-
451-
const data = await Promise.all(models.map(async (model: FailedJobModel) => {
452-
const instance = new FailedJobModel(model)
453-
454-
const results = await instance.mapWith(model)
455-
456-
return new FailedJobModel(results)
457-
}))
458-
459-
return data
446+
return await instance.applyGet()
460447
}
461448

462449
has(relation: string): FailedJobModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class JobModel {
415415
.executeTakeFirst()
416416
}
417417

418-
async get(): Promise<JobModel[]> {
418+
async applyGet(): Promise<JobModel[]> {
419419
let models
420420

421421
if (this.hasSelect) {
@@ -436,27 +436,14 @@ export class JobModel {
436436
return data
437437
}
438438

439+
async get(): Promise<JobModel[]> {
440+
return await this.applyGet()
441+
}
442+
439443
static async get(): Promise<JobModel[]> {
440444
const instance = new JobModel(null)
441445

442-
let models
443-
444-
if (instance.hasSelect) {
445-
models = await instance.selectFromQuery.execute()
446-
}
447-
else {
448-
models = await instance.selectFromQuery.selectAll().execute()
449-
}
450-
451-
const data = await Promise.all(models.map(async (model: JobModel) => {
452-
const instance = new JobModel(model)
453-
454-
const results = await instance.mapWith(model)
455-
456-
return new JobModel(results)
457-
}))
458-
459-
return data
446+
return await instance.applyGet()
460447
}
461448

462449
has(relation: string): JobModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export class PaymentMethodModel {
473473
.executeTakeFirst()
474474
}
475475

476-
async get(): Promise<PaymentMethodModel[]> {
476+
async applyGet(): Promise<PaymentMethodModel[]> {
477477
let models
478478

479479
if (this.hasSelect) {
@@ -494,27 +494,14 @@ export class PaymentMethodModel {
494494
return data
495495
}
496496

497+
async get(): Promise<PaymentMethodModel[]> {
498+
return await this.applyGet()
499+
}
500+
497501
static async get(): Promise<PaymentMethodModel[]> {
498502
const instance = new PaymentMethodModel(null)
499503

500-
let models
501-
502-
if (instance.hasSelect) {
503-
models = await instance.selectFromQuery.execute()
504-
}
505-
else {
506-
models = await instance.selectFromQuery.selectAll().execute()
507-
}
508-
509-
const data = await Promise.all(models.map(async (model: PaymentMethodModel) => {
510-
const instance = new PaymentMethodModel(model)
511-
512-
const results = await instance.mapWith(model)
513-
514-
return new PaymentMethodModel(results)
515-
}))
516-
517-
return data
504+
return await instance.applyGet()
518505
}
519506

520507
has(relation: string): PaymentMethodModel {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class PostModel {
405405
.executeTakeFirst()
406406
}
407407

408-
async get(): Promise<PostModel[]> {
408+
async applyGet(): Promise<PostModel[]> {
409409
let models
410410

411411
if (this.hasSelect) {
@@ -426,27 +426,14 @@ export class PostModel {
426426
return data
427427
}
428428

429+
async get(): Promise<PostModel[]> {
430+
return await this.applyGet()
431+
}
432+
429433
static async get(): Promise<PostModel[]> {
430434
const instance = new PostModel(null)
431435

432-
let models
433-
434-
if (instance.hasSelect) {
435-
models = await instance.selectFromQuery.execute()
436-
}
437-
else {
438-
models = await instance.selectFromQuery.selectAll().execute()
439-
}
440-
441-
const data = await Promise.all(models.map(async (model: PostModel) => {
442-
const instance = new PostModel(model)
443-
444-
const results = await instance.mapWith(model)
445-
446-
return new PostModel(results)
447-
}))
448-
449-
return data
436+
return await instance.applyGet()
450437
}
451438

452439
has(relation: string): PostModel {

0 commit comments

Comments
 (0)