Skip to content

Commit 69d612c

Browse files
chore: wip
1 parent 55a2b04 commit 69d612c

File tree

17 files changed

+545
-1
lines changed

17 files changed

+545
-1
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,38 @@ export async function generateModelString(
13551355
13561356
return data
13571357
}
1358+
1359+
static async latest(): Promise<${modelName}Type | undefined> {
1360+
const model = await db.selectFrom('${tableName}')
1361+
.selectAll()
1362+
.orderBy('created_at', 'desc')
1363+
.executeTakeFirst()
1364+
1365+
if (!model)
1366+
return undefined
1367+
1368+
const instance = new ${modelName}Model(null)
1369+
const result = await instance.mapWith(model)
1370+
const data = new ${modelName}Model(result as ${modelName}Type)
1371+
1372+
return data
1373+
}
1374+
1375+
static async oldest(): Promise<${modelName}Type | undefined> {
1376+
const model = await db.selectFrom('${tableName}')
1377+
.selectAll()
1378+
.orderBy('created_at', 'asc')
1379+
.executeTakeFirst()
1380+
1381+
if (!model)
1382+
return undefined
1383+
1384+
const instance = new ${modelName}Model(null)
1385+
const result = await instance.mapWith(model)
1386+
const data = new ${modelName}Model(result as ${modelName}Type)
1387+
1388+
return data
1389+
}
13581390
13591391
static async firstOrCreate(
13601392
condition: Partial<${modelName}Type>,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,38 @@ export class AccessTokenModel {
693693
return data
694694
}
695695

696+
static async latest(): Promise<AccessTokenType | undefined> {
697+
const model = await db.selectFrom('personal_access_tokens')
698+
.selectAll()
699+
.orderBy('created_at', 'desc')
700+
.executeTakeFirst()
701+
702+
if (!model)
703+
return undefined
704+
705+
const instance = new AccessTokenModel(null)
706+
const result = await instance.mapWith(model)
707+
const data = new AccessTokenModel(result as AccessTokenType)
708+
709+
return data
710+
}
711+
712+
static async oldest(): Promise<AccessTokenType | undefined> {
713+
const model = await db.selectFrom('personal_access_tokens')
714+
.selectAll()
715+
.orderBy('created_at', 'asc')
716+
.executeTakeFirst()
717+
718+
if (!model)
719+
return undefined
720+
721+
const instance = new AccessTokenModel(null)
722+
const result = await instance.mapWith(model)
723+
const data = new AccessTokenModel(result as AccessTokenType)
724+
725+
return data
726+
}
727+
696728
static async firstOrCreate(
697729
condition: Partial<AccessTokenType>,
698730
newAccessToken: NewAccessToken,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,38 @@ export class DeploymentModel {
736736
return data
737737
}
738738

739+
static async latest(): Promise<DeploymentType | undefined> {
740+
const model = await db.selectFrom('deployments')
741+
.selectAll()
742+
.orderBy('created_at', 'desc')
743+
.executeTakeFirst()
744+
745+
if (!model)
746+
return undefined
747+
748+
const instance = new DeploymentModel(null)
749+
const result = await instance.mapWith(model)
750+
const data = new DeploymentModel(result as DeploymentType)
751+
752+
return data
753+
}
754+
755+
static async oldest(): Promise<DeploymentType | undefined> {
756+
const model = await db.selectFrom('deployments')
757+
.selectAll()
758+
.orderBy('created_at', 'asc')
759+
.executeTakeFirst()
760+
761+
if (!model)
762+
return undefined
763+
764+
const instance = new DeploymentModel(null)
765+
const result = await instance.mapWith(model)
766+
const data = new DeploymentModel(result as DeploymentType)
767+
768+
return data
769+
}
770+
739771
static async firstOrCreate(
740772
condition: Partial<DeploymentType>,
741773
newDeployment: NewDeployment,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,38 @@ export class ErrorModel {
691691
return data
692692
}
693693

694+
static async latest(): Promise<ErrorType | undefined> {
695+
const model = await db.selectFrom('errors')
696+
.selectAll()
697+
.orderBy('created_at', 'desc')
698+
.executeTakeFirst()
699+
700+
if (!model)
701+
return undefined
702+
703+
const instance = new ErrorModel(null)
704+
const result = await instance.mapWith(model)
705+
const data = new ErrorModel(result as ErrorType)
706+
707+
return data
708+
}
709+
710+
static async oldest(): Promise<ErrorType | undefined> {
711+
const model = await db.selectFrom('errors')
712+
.selectAll()
713+
.orderBy('created_at', 'asc')
714+
.executeTakeFirst()
715+
716+
if (!model)
717+
return undefined
718+
719+
const instance = new ErrorModel(null)
720+
const result = await instance.mapWith(model)
721+
const data = new ErrorModel(result as ErrorType)
722+
723+
return data
724+
}
725+
694726
static async firstOrCreate(
695727
condition: Partial<ErrorType>,
696728
newError: NewError,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,38 @@ export class FailedJobModel {
691691
return data
692692
}
693693

694+
static async latest(): Promise<FailedJobType | undefined> {
695+
const model = await db.selectFrom('failed_jobs')
696+
.selectAll()
697+
.orderBy('created_at', 'desc')
698+
.executeTakeFirst()
699+
700+
if (!model)
701+
return undefined
702+
703+
const instance = new FailedJobModel(null)
704+
const result = await instance.mapWith(model)
705+
const data = new FailedJobModel(result as FailedJobType)
706+
707+
return data
708+
}
709+
710+
static async oldest(): Promise<FailedJobType | undefined> {
711+
const model = await db.selectFrom('failed_jobs')
712+
.selectAll()
713+
.orderBy('created_at', 'asc')
714+
.executeTakeFirst()
715+
716+
if (!model)
717+
return undefined
718+
719+
const instance = new FailedJobModel(null)
720+
const result = await instance.mapWith(model)
721+
const data = new FailedJobModel(result as FailedJobType)
722+
723+
return data
724+
}
725+
694726
static async firstOrCreate(
695727
condition: Partial<FailedJobType>,
696728
newFailedJob: NewFailedJob,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,38 @@ export class JobModel {
691691
return data
692692
}
693693

694+
static async latest(): Promise<JobType | undefined> {
695+
const model = await db.selectFrom('jobs')
696+
.selectAll()
697+
.orderBy('created_at', 'desc')
698+
.executeTakeFirst()
699+
700+
if (!model)
701+
return undefined
702+
703+
const instance = new JobModel(null)
704+
const result = await instance.mapWith(model)
705+
const data = new JobModel(result as JobType)
706+
707+
return data
708+
}
709+
710+
static async oldest(): Promise<JobType | undefined> {
711+
const model = await db.selectFrom('jobs')
712+
.selectAll()
713+
.orderBy('created_at', 'asc')
714+
.executeTakeFirst()
715+
716+
if (!model)
717+
return undefined
718+
719+
const instance = new JobModel(null)
720+
const result = await instance.mapWith(model)
721+
const data = new JobModel(result as JobType)
722+
723+
return data
724+
}
725+
694726
static async firstOrCreate(
695727
condition: Partial<JobType>,
696728
newJob: NewJob,

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,38 @@ export class PaymentMethodModel {
746746
return data
747747
}
748748

749+
static async latest(): Promise<PaymentMethodType | undefined> {
750+
const model = await db.selectFrom('payment_methods')
751+
.selectAll()
752+
.orderBy('created_at', 'desc')
753+
.executeTakeFirst()
754+
755+
if (!model)
756+
return undefined
757+
758+
const instance = new PaymentMethodModel(null)
759+
const result = await instance.mapWith(model)
760+
const data = new PaymentMethodModel(result as PaymentMethodType)
761+
762+
return data
763+
}
764+
765+
static async oldest(): Promise<PaymentMethodType | undefined> {
766+
const model = await db.selectFrom('payment_methods')
767+
.selectAll()
768+
.orderBy('created_at', 'asc')
769+
.executeTakeFirst()
770+
771+
if (!model)
772+
return undefined
773+
774+
const instance = new PaymentMethodModel(null)
775+
const result = await instance.mapWith(model)
776+
const data = new PaymentMethodModel(result as PaymentMethodType)
777+
778+
return data
779+
}
780+
749781
static async firstOrCreate(
750782
condition: Partial<PaymentMethodType>,
751783
newPaymentMethod: NewPaymentMethod,
@@ -1008,7 +1040,7 @@ export class PaymentMethodModel {
10081040
throw new HttpError(500, 'Relation Error!')
10091041

10101042
const results = await db.selectFrom('transactions')
1011-
.where('paymentmethod_id', '=', this.id)
1043+
.where('transaction_id', '=', this.id)
10121044
.limit(5)
10131045
.selectAll()
10141046
.execute()

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,38 @@ export class PostModel {
671671
return data
672672
}
673673

674+
static async latest(): Promise<PostType | undefined> {
675+
const model = await db.selectFrom('posts')
676+
.selectAll()
677+
.orderBy('created_at', 'desc')
678+
.executeTakeFirst()
679+
680+
if (!model)
681+
return undefined
682+
683+
const instance = new PostModel(null)
684+
const result = await instance.mapWith(model)
685+
const data = new PostModel(result as PostType)
686+
687+
return data
688+
}
689+
690+
static async oldest(): Promise<PostType | undefined> {
691+
const model = await db.selectFrom('posts')
692+
.selectAll()
693+
.orderBy('created_at', 'asc')
694+
.executeTakeFirst()
695+
696+
if (!model)
697+
return undefined
698+
699+
const instance = new PostModel(null)
700+
const result = await instance.mapWith(model)
701+
const data = new PostModel(result as PostType)
702+
703+
return data
704+
}
705+
674706
static async firstOrCreate(
675707
condition: Partial<PostType>,
676708
newPost: NewPost,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,38 @@ export class ProductModel {
723723
return data
724724
}
725725

726+
static async latest(): Promise<ProductType | undefined> {
727+
const model = await db.selectFrom('products')
728+
.selectAll()
729+
.orderBy('created_at', 'desc')
730+
.executeTakeFirst()
731+
732+
if (!model)
733+
return undefined
734+
735+
const instance = new ProductModel(null)
736+
const result = await instance.mapWith(model)
737+
const data = new ProductModel(result as ProductType)
738+
739+
return data
740+
}
741+
742+
static async oldest(): Promise<ProductType | undefined> {
743+
const model = await db.selectFrom('products')
744+
.selectAll()
745+
.orderBy('created_at', 'asc')
746+
.executeTakeFirst()
747+
748+
if (!model)
749+
return undefined
750+
751+
const instance = new ProductModel(null)
752+
const result = await instance.mapWith(model)
753+
const data = new ProductModel(result as ProductType)
754+
755+
return data
756+
}
757+
726758
static async firstOrCreate(
727759
condition: Partial<ProductType>,
728760
newProduct: NewProduct,

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,38 @@ export class ProjectModel {
680680
return data
681681
}
682682

683+
static async latest(): Promise<ProjectType | undefined> {
684+
const model = await db.selectFrom('projects')
685+
.selectAll()
686+
.orderBy('created_at', 'desc')
687+
.executeTakeFirst()
688+
689+
if (!model)
690+
return undefined
691+
692+
const instance = new ProjectModel(null)
693+
const result = await instance.mapWith(model)
694+
const data = new ProjectModel(result as ProjectType)
695+
696+
return data
697+
}
698+
699+
static async oldest(): Promise<ProjectType | undefined> {
700+
const model = await db.selectFrom('projects')
701+
.selectAll()
702+
.orderBy('created_at', 'asc')
703+
.executeTakeFirst()
704+
705+
if (!model)
706+
return undefined
707+
708+
const instance = new ProjectModel(null)
709+
const result = await instance.mapWith(model)
710+
const data = new ProjectModel(result as ProjectType)
711+
712+
return data
713+
}
714+
683715
static async firstOrCreate(
684716
condition: Partial<ProjectType>,
685717
newProject: NewProject,

0 commit comments

Comments
 (0)