Skip to content

Commit 3e100be

Browse files
chore: wip
1 parent 14f526e commit 3e100be

35 files changed

+39
-443
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,18 @@ export class BaseOrm<T, C, J> {
450450
return this.applyTake(count)
451451
}
452452

453-
async count(): Promise<number> {
453+
async applyCount(): Promise<number> {
454454
const result = await this.selectFromQuery
455455
.select(sql`COUNT(*) as count`)
456456
.executeTakeFirst()
457457

458458
return result.count || 0
459459
}
460460

461+
async count(): Promise<number> {
462+
return this.applyCount()
463+
}
464+
461465
applyOrderBy(column: keyof C, order: 'asc' | 'desc'): this {
462466
this.selectFromQuery = this.selectFromQuery.orderBy(column, order)
463467

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,19 +1264,7 @@ export async function generateModelString(
12641264
static async count(): Promise<number> {
12651265
const instance = new ${modelName}Model(undefined)
12661266
1267-
const result = await instance.selectFromQuery
1268-
.select(sql\`COUNT(*) as count\`)
1269-
.executeTakeFirst()
1270-
1271-
return result.count || 0
1272-
}
1273-
1274-
async count(): Promise<number> {
1275-
const result = await this.selectFromQuery
1276-
.select(sql\`COUNT(*) as count\`)
1277-
.executeTakeFirst()
1278-
1279-
return result.count || 0
1267+
return instance.applyCount()
12801268
}
12811269
12821270
static async max(field: keyof ${modelName}Model): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,19 +487,7 @@ export class AccessTokenModel extends BaseOrm<AccessTokenModel, PersonalAccessTo
487487
static async count(): Promise<number> {
488488
const instance = new AccessTokenModel(undefined)
489489

490-
const result = await instance.selectFromQuery
491-
.select(sql`COUNT(*) as count`)
492-
.executeTakeFirst()
493-
494-
return result.count || 0
495-
}
496-
497-
async count(): Promise<number> {
498-
const result = await this.selectFromQuery
499-
.select(sql`COUNT(*) as count`)
500-
.executeTakeFirst()
501-
502-
return result.count || 0
490+
return instance.applyCount()
503491
}
504492

505493
static async max(field: keyof AccessTokenModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,7 @@ export class CouponModel extends BaseOrm<CouponModel, CouponsTable, CouponJsonRe
527527
static async count(): Promise<number> {
528528
const instance = new CouponModel(undefined)
529529

530-
const result = await instance.selectFromQuery
531-
.select(sql`COUNT(*) as count`)
532-
.executeTakeFirst()
533-
534-
return result.count || 0
535-
}
536-
537-
async count(): Promise<number> {
538-
const result = await this.selectFromQuery
539-
.select(sql`COUNT(*) as count`)
540-
.executeTakeFirst()
541-
542-
return result.count || 0
530+
return instance.applyCount()
543531
}
544532

545533
static async max(field: keyof CouponModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,7 @@ export class CustomerModel extends BaseOrm<CustomerModel, CustomersTable, Custom
472472
static async count(): Promise<number> {
473473
const instance = new CustomerModel(undefined)
474474

475-
const result = await instance.selectFromQuery
476-
.select(sql`COUNT(*) as count`)
477-
.executeTakeFirst()
478-
479-
return result.count || 0
480-
}
481-
482-
async count(): Promise<number> {
483-
const result = await this.selectFromQuery
484-
.select(sql`COUNT(*) as count`)
485-
.executeTakeFirst()
486-
487-
return result.count || 0
475+
return instance.applyCount()
488476
}
489477

490478
static async max(field: keyof CustomerModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,7 @@ export class DeploymentModel extends BaseOrm<DeploymentModel, DeploymentsTable,
457457
static async count(): Promise<number> {
458458
const instance = new DeploymentModel(undefined)
459459

460-
const result = await instance.selectFromQuery
461-
.select(sql`COUNT(*) as count`)
462-
.executeTakeFirst()
463-
464-
return result.count || 0
465-
}
466-
467-
async count(): Promise<number> {
468-
const result = await this.selectFromQuery
469-
.select(sql`COUNT(*) as count`)
470-
.executeTakeFirst()
471-
472-
return result.count || 0
460+
return instance.applyCount()
473461
}
474462

475463
static async max(field: keyof DeploymentModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,7 @@ export class ErrorModel extends BaseOrm<ErrorModel, ErrorsTable, ErrorJsonRespon
417417
static async count(): Promise<number> {
418418
const instance = new ErrorModel(undefined)
419419

420-
const result = await instance.selectFromQuery
421-
.select(sql`COUNT(*) as count`)
422-
.executeTakeFirst()
423-
424-
return result.count || 0
425-
}
426-
427-
async count(): Promise<number> {
428-
const result = await this.selectFromQuery
429-
.select(sql`COUNT(*) as count`)
430-
.executeTakeFirst()
431-
432-
return result.count || 0
420+
return instance.applyCount()
433421
}
434422

435423
static async max(field: keyof ErrorModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,7 @@ export class FailedJobModel extends BaseOrm<FailedJobModel, FailedJobsTable, Fai
417417
static async count(): Promise<number> {
418418
const instance = new FailedJobModel(undefined)
419419

420-
const result = await instance.selectFromQuery
421-
.select(sql`COUNT(*) as count`)
422-
.executeTakeFirst()
423-
424-
return result.count || 0
425-
}
426-
427-
async count(): Promise<number> {
428-
const result = await this.selectFromQuery
429-
.select(sql`COUNT(*) as count`)
430-
.executeTakeFirst()
431-
432-
return result.count || 0
420+
return instance.applyCount()
433421
}
434422

435423
static async max(field: keyof FailedJobModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -536,19 +536,7 @@ export class GiftCardModel extends BaseOrm<GiftCardModel, GiftCardsTable, GiftCa
536536
static async count(): Promise<number> {
537537
const instance = new GiftCardModel(undefined)
538538

539-
const result = await instance.selectFromQuery
540-
.select(sql`COUNT(*) as count`)
541-
.executeTakeFirst()
542-
543-
return result.count || 0
544-
}
545-
546-
async count(): Promise<number> {
547-
const result = await this.selectFromQuery
548-
.select(sql`COUNT(*) as count`)
549-
.executeTakeFirst()
550-
551-
return result.count || 0
539+
return instance.applyCount()
552540
}
553541

554542
static async max(field: keyof GiftCardModel): Promise<number> {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,7 @@ export class JobModel extends BaseOrm<JobModel, JobsTable, JobJsonResponse> {
417417
static async count(): Promise<number> {
418418
const instance = new JobModel(undefined)
419419

420-
const result = await instance.selectFromQuery
421-
.select(sql`COUNT(*) as count`)
422-
.executeTakeFirst()
423-
424-
return result.count || 0
425-
}
426-
427-
async count(): Promise<number> {
428-
const result = await this.selectFromQuery
429-
.select(sql`COUNT(*) as count`)
430-
.executeTakeFirst()
431-
432-
return result.count || 0
420+
return instance.applyCount()
433421
}
434422

435423
static async max(field: keyof JobModel): Promise<number> {

0 commit comments

Comments
 (0)