Skip to content

Commit fede6e9

Browse files
chore: wip
1 parent 2600917 commit fede6e9

File tree

17 files changed

+205
-1
lines changed

17 files changed

+205
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,19 @@ export async function generateModelString(
913913
const model = await this.selectFromQuery.selectAll().execute()
914914
return model.map((modelItem: ${modelName}Model) => modelItem[field])
915915
}
916-
916+
917+
async max(field: keyof ${modelName}Model): Promise<number> {
918+
return await this.selectFromQuery
919+
.select(sql\`MAX(\${sql.raw(field as string)}) \`)
920+
.executeTakeFirst()
921+
}
922+
923+
async min(field: keyof ${modelName}Model): Promise<number> {
924+
return await this.selectFromQuery
925+
.select(sql\`MIN(\${sql.raw(field as string)}) \`)
926+
.executeTakeFirst()
927+
}
928+
917929
static async get(): Promise<${modelName}Model[]> {
918930
const instance = new ${modelName}Model(null)
919931

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ export class AccessTokenModel {
249249
return model.map((modelItem: AccessTokenModel) => modelItem[field])
250250
}
251251

252+
async max(field: keyof AccessTokenModel): Promise<number> {
253+
return await this.selectFromQuery
254+
.select(sql`MAX(${sql.raw(field as string)}) `)
255+
.executeTakeFirst()
256+
}
257+
258+
async min(field: keyof AccessTokenModel): Promise<number> {
259+
return await this.selectFromQuery
260+
.select(sql`MIN(${sql.raw(field as string)}) `)
261+
.executeTakeFirst()
262+
}
263+
252264
static async get(): Promise<AccessTokenModel[]> {
253265
const instance = new AccessTokenModel(null)
254266

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ export class DeploymentModel {
262262
return model.map((modelItem: DeploymentModel) => modelItem[field])
263263
}
264264

265+
async max(field: keyof DeploymentModel): Promise<number> {
266+
return await this.selectFromQuery
267+
.select(sql`MAX(${sql.raw(field as string)}) `)
268+
.executeTakeFirst()
269+
}
270+
271+
async min(field: keyof DeploymentModel): Promise<number> {
272+
return await this.selectFromQuery
273+
.select(sql`MIN(${sql.raw(field as string)}) `)
274+
.executeTakeFirst()
275+
}
276+
265277
static async get(): Promise<DeploymentModel[]> {
266278
const instance = new DeploymentModel(null)
267279

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ export class ErrorModel {
239239
return model.map((modelItem: ErrorModel) => modelItem[field])
240240
}
241241

242+
async max(field: keyof ErrorModel): Promise<number> {
243+
return await this.selectFromQuery
244+
.select(sql`MAX(${sql.raw(field as string)}) `)
245+
.executeTakeFirst()
246+
}
247+
248+
async min(field: keyof ErrorModel): Promise<number> {
249+
return await this.selectFromQuery
250+
.select(sql`MIN(${sql.raw(field as string)}) `)
251+
.executeTakeFirst()
252+
}
253+
242254
static async get(): Promise<ErrorModel[]> {
243255
const instance = new ErrorModel(null)
244256

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ export class FailedJobModel {
239239
return model.map((modelItem: FailedJobModel) => modelItem[field])
240240
}
241241

242+
async max(field: keyof FailedJobModel): Promise<number> {
243+
return await this.selectFromQuery
244+
.select(sql`MAX(${sql.raw(field as string)}) `)
245+
.executeTakeFirst()
246+
}
247+
248+
async min(field: keyof FailedJobModel): Promise<number> {
249+
return await this.selectFromQuery
250+
.select(sql`MIN(${sql.raw(field as string)}) `)
251+
.executeTakeFirst()
252+
}
253+
242254
static async get(): Promise<FailedJobModel[]> {
243255
const instance = new FailedJobModel(null)
244256

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ export class JobModel {
239239
return model.map((modelItem: JobModel) => modelItem[field])
240240
}
241241

242+
async max(field: keyof JobModel): Promise<number> {
243+
return await this.selectFromQuery
244+
.select(sql`MAX(${sql.raw(field as string)}) `)
245+
.executeTakeFirst()
246+
}
247+
248+
async min(field: keyof JobModel): Promise<number> {
249+
return await this.selectFromQuery
250+
.select(sql`MIN(${sql.raw(field as string)}) `)
251+
.executeTakeFirst()
252+
}
253+
242254
static async get(): Promise<JobModel[]> {
243255
const instance = new JobModel(null)
244256

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ export class PaymentMethodModel {
272272
return model.map((modelItem: PaymentMethodModel) => modelItem[field])
273273
}
274274

275+
async max(field: keyof PaymentMethodModel): Promise<number> {
276+
return await this.selectFromQuery
277+
.select(sql`MAX(${sql.raw(field as string)}) `)
278+
.executeTakeFirst()
279+
}
280+
281+
async min(field: keyof PaymentMethodModel): Promise<number> {
282+
return await this.selectFromQuery
283+
.select(sql`MIN(${sql.raw(field as string)}) `)
284+
.executeTakeFirst()
285+
}
286+
275287
static async get(): Promise<PaymentMethodModel[]> {
276288
const instance = new PaymentMethodModel(null)
277289

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ export class PostModel {
243243
return model.map((modelItem: PostModel) => modelItem[field])
244244
}
245245

246+
async max(field: keyof PostModel): Promise<number> {
247+
return await this.selectFromQuery
248+
.select(sql`MAX(${sql.raw(field as string)}) `)
249+
.executeTakeFirst()
250+
}
251+
252+
async min(field: keyof PostModel): Promise<number> {
253+
return await this.selectFromQuery
254+
.select(sql`MIN(${sql.raw(field as string)}) `)
255+
.executeTakeFirst()
256+
}
257+
246258
static async get(): Promise<PostModel[]> {
247259
const instance = new PostModel(null)
248260

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ export class ProductModel {
249249
return model.map((modelItem: ProductModel) => modelItem[field])
250250
}
251251

252+
async max(field: keyof ProductModel): Promise<number> {
253+
return await this.selectFromQuery
254+
.select(sql`MAX(${sql.raw(field as string)}) `)
255+
.executeTakeFirst()
256+
}
257+
258+
async min(field: keyof ProductModel): Promise<number> {
259+
return await this.selectFromQuery
260+
.select(sql`MIN(${sql.raw(field as string)}) `)
261+
.executeTakeFirst()
262+
}
263+
252264
static async get(): Promise<ProductModel[]> {
253265
const instance = new ProductModel(null)
254266

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ export class ProjectModel {
236236
return model.map((modelItem: ProjectModel) => modelItem[field])
237237
}
238238

239+
async max(field: keyof ProjectModel): Promise<number> {
240+
return await this.selectFromQuery
241+
.select(sql`MAX(${sql.raw(field as string)}) `)
242+
.executeTakeFirst()
243+
}
244+
245+
async min(field: keyof ProjectModel): Promise<number> {
246+
return await this.selectFromQuery
247+
.select(sql`MIN(${sql.raw(field as string)}) `)
248+
.executeTakeFirst()
249+
}
250+
239251
static async get(): Promise<ProjectModel[]> {
240252
const instance = new ProjectModel(null)
241253

0 commit comments

Comments
 (0)