Skip to content

Commit 0c23247

Browse files
chore: wip
1 parent 318536d commit 0c23247

File tree

18 files changed

+234
-90
lines changed

18 files changed

+234
-90
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,13 +1596,11 @@ export async function generateModelString(
15961596
15971597
return await instance.applyPaginate(options)
15981598
}
1599-
1600-
static async create(new${modelName}: New${modelName}): Promise<${modelName}Model> {
1601-
const instance = new ${modelName}Model(null)
16021599
1600+
async applyCreate(new${modelName}: New${modelName}): Promise<${modelName}Model> {
16031601
const filteredValues = Object.fromEntries(
16041602
Object.entries(new${modelName}).filter(([key]) =>
1605-
!instance.guarded.includes(key) && instance.fillable.includes(key)
1603+
!this.guarded.includes(key) && this.fillable.includes(key)
16061604
),
16071605
) as New${modelName}
16081606
@@ -1612,13 +1610,23 @@ export async function generateModelString(
16121610
.values(filteredValues)
16131611
.executeTakeFirst()
16141612
1615-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as ${modelName}Model
1613+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as ${modelName}Model
16161614
16171615
if (model)
16181616
dispatch('${formattedModelName}:created', model)
16191617
16201618
return model
16211619
}
1620+
1621+
async create(new${modelName}: New${modelName}): Promise<${modelName}Model> {
1622+
return await this.create(new${modelName})
1623+
}
1624+
1625+
static async create(new${modelName}: New${modelName}): Promise<${modelName}Model> {
1626+
const instance = new ${modelName}Model(null)
1627+
1628+
return await instance.create(new${modelName})
1629+
}
16221630
16231631
static async createMany(new${modelName}: New${modelName}[]): Promise<void> {
16241632
const instance = new ${modelName}Model(null)

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,27 +827,35 @@ export class AccessTokenModel {
827827
return await instance.applyPaginate(options)
828828
}
829829

830-
static async create(newAccessToken: NewAccessToken): Promise<AccessTokenModel> {
831-
const instance = new AccessTokenModel(null)
832-
830+
async applyCreate(newAccessToken: NewAccessToken): Promise<AccessTokenModel> {
833831
const filteredValues = Object.fromEntries(
834832
Object.entries(newAccessToken).filter(([key]) =>
835-
!instance.guarded.includes(key) && instance.fillable.includes(key),
833+
!this.guarded.includes(key) && this.fillable.includes(key),
836834
),
837835
) as NewAccessToken
838836

839837
const result = await DB.instance.insertInto('personal_access_tokens')
840838
.values(filteredValues)
841839
.executeTakeFirst()
842840

843-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as AccessTokenModel
841+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as AccessTokenModel
844842

845843
if (model)
846844
dispatch('accesstoken:created', model)
847845

848846
return model
849847
}
850848

849+
async create(newAccessToken: NewAccessToken): Promise<AccessTokenModel> {
850+
return await this.create(newAccessToken)
851+
}
852+
853+
static async create(newAccessToken: NewAccessToken): Promise<AccessTokenModel> {
854+
const instance = new AccessTokenModel(null)
855+
856+
return await instance.create(newAccessToken)
857+
}
858+
851859
static async createMany(newAccessToken: NewAccessToken[]): Promise<void> {
852860
const instance = new AccessTokenModel(null)
853861

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,27 +850,35 @@ export class ActivityModel {
850850
return await instance.applyPaginate(options)
851851
}
852852

853-
static async create(newActivity: NewActivity): Promise<ActivityModel> {
854-
const instance = new ActivityModel(null)
855-
853+
async applyCreate(newActivity: NewActivity): Promise<ActivityModel> {
856854
const filteredValues = Object.fromEntries(
857855
Object.entries(newActivity).filter(([key]) =>
858-
!instance.guarded.includes(key) && instance.fillable.includes(key),
856+
!this.guarded.includes(key) && this.fillable.includes(key),
859857
),
860858
) as NewActivity
861859

862860
const result = await DB.instance.insertInto('activities')
863861
.values(filteredValues)
864862
.executeTakeFirst()
865863

866-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as ActivityModel
864+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as ActivityModel
867865

868866
if (model)
869867
dispatch('activity:created', model)
870868

871869
return model
872870
}
873871

872+
async create(newActivity: NewActivity): Promise<ActivityModel> {
873+
return await this.create(newActivity)
874+
}
875+
876+
static async create(newActivity: NewActivity): Promise<ActivityModel> {
877+
const instance = new ActivityModel(null)
878+
879+
return await instance.create(newActivity)
880+
}
881+
874882
static async createMany(newActivity: NewActivity[]): Promise<void> {
875883
const instance = new ActivityModel(null)
876884

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,10 @@ export class DeploymentModel {
864864
return await instance.applyPaginate(options)
865865
}
866866

867-
static async create(newDeployment: NewDeployment): Promise<DeploymentModel> {
868-
const instance = new DeploymentModel(null)
869-
867+
async applyCreate(newDeployment: NewDeployment): Promise<DeploymentModel> {
870868
const filteredValues = Object.fromEntries(
871869
Object.entries(newDeployment).filter(([key]) =>
872-
!instance.guarded.includes(key) && instance.fillable.includes(key),
870+
!this.guarded.includes(key) && this.fillable.includes(key),
873871
),
874872
) as NewDeployment
875873

@@ -879,14 +877,24 @@ export class DeploymentModel {
879877
.values(filteredValues)
880878
.executeTakeFirst()
881879

882-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as DeploymentModel
880+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as DeploymentModel
883881

884882
if (model)
885883
dispatch('deployment:created', model)
886884

887885
return model
888886
}
889887

888+
async create(newDeployment: NewDeployment): Promise<DeploymentModel> {
889+
return await this.create(newDeployment)
890+
}
891+
892+
static async create(newDeployment: NewDeployment): Promise<DeploymentModel> {
893+
const instance = new DeploymentModel(null)
894+
895+
return await instance.create(newDeployment)
896+
}
897+
890898
static async createMany(newDeployment: NewDeployment[]): Promise<void> {
891899
const instance = new DeploymentModel(null)
892900

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,27 +823,35 @@ export class ErrorModel {
823823
return await instance.applyPaginate(options)
824824
}
825825

826-
static async create(newError: NewError): Promise<ErrorModel> {
827-
const instance = new ErrorModel(null)
828-
826+
async applyCreate(newError: NewError): Promise<ErrorModel> {
829827
const filteredValues = Object.fromEntries(
830828
Object.entries(newError).filter(([key]) =>
831-
!instance.guarded.includes(key) && instance.fillable.includes(key),
829+
!this.guarded.includes(key) && this.fillable.includes(key),
832830
),
833831
) as NewError
834832

835833
const result = await DB.instance.insertInto('errors')
836834
.values(filteredValues)
837835
.executeTakeFirst()
838836

839-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as ErrorModel
837+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as ErrorModel
840838

841839
if (model)
842840
dispatch('error:created', model)
843841

844842
return model
845843
}
846844

845+
async create(newError: NewError): Promise<ErrorModel> {
846+
return await this.create(newError)
847+
}
848+
849+
static async create(newError: NewError): Promise<ErrorModel> {
850+
const instance = new ErrorModel(null)
851+
852+
return await instance.create(newError)
853+
}
854+
847855
static async createMany(newError: NewError[]): Promise<void> {
848856
const instance = new ErrorModel(null)
849857

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,27 +823,35 @@ export class FailedJobModel {
823823
return await instance.applyPaginate(options)
824824
}
825825

826-
static async create(newFailedJob: NewFailedJob): Promise<FailedJobModel> {
827-
const instance = new FailedJobModel(null)
828-
826+
async applyCreate(newFailedJob: NewFailedJob): Promise<FailedJobModel> {
829827
const filteredValues = Object.fromEntries(
830828
Object.entries(newFailedJob).filter(([key]) =>
831-
!instance.guarded.includes(key) && instance.fillable.includes(key),
829+
!this.guarded.includes(key) && this.fillable.includes(key),
832830
),
833831
) as NewFailedJob
834832

835833
const result = await DB.instance.insertInto('failed_jobs')
836834
.values(filteredValues)
837835
.executeTakeFirst()
838836

839-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as FailedJobModel
837+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as FailedJobModel
840838

841839
if (model)
842840
dispatch('failedjob:created', model)
843841

844842
return model
845843
}
846844

845+
async create(newFailedJob: NewFailedJob): Promise<FailedJobModel> {
846+
return await this.create(newFailedJob)
847+
}
848+
849+
static async create(newFailedJob: NewFailedJob): Promise<FailedJobModel> {
850+
const instance = new FailedJobModel(null)
851+
852+
return await instance.create(newFailedJob)
853+
}
854+
847855
static async createMany(newFailedJob: NewFailedJob[]): Promise<void> {
848856
const instance = new FailedJobModel(null)
849857

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,27 +823,35 @@ export class JobModel {
823823
return await instance.applyPaginate(options)
824824
}
825825

826-
static async create(newJob: NewJob): Promise<JobModel> {
827-
const instance = new JobModel(null)
828-
826+
async applyCreate(newJob: NewJob): Promise<JobModel> {
829827
const filteredValues = Object.fromEntries(
830828
Object.entries(newJob).filter(([key]) =>
831-
!instance.guarded.includes(key) && instance.fillable.includes(key),
829+
!this.guarded.includes(key) && this.fillable.includes(key),
832830
),
833831
) as NewJob
834832

835833
const result = await DB.instance.insertInto('jobs')
836834
.values(filteredValues)
837835
.executeTakeFirst()
838836

839-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as JobModel
837+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as JobModel
840838

841839
if (model)
842840
dispatch('job:created', model)
843841

844842
return model
845843
}
846844

845+
async create(newJob: NewJob): Promise<JobModel> {
846+
return await this.create(newJob)
847+
}
848+
849+
static async create(newJob: NewJob): Promise<JobModel> {
850+
const instance = new JobModel(null)
851+
852+
return await instance.create(newJob)
853+
}
854+
847855
static async createMany(newJob: NewJob[]): Promise<void> {
848856
const instance = new JobModel(null)
849857

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,10 @@ export class PaymentMethodModel {
871871
return await instance.applyPaginate(options)
872872
}
873873

874-
static async create(newPaymentMethod: NewPaymentMethod): Promise<PaymentMethodModel> {
875-
const instance = new PaymentMethodModel(null)
876-
874+
async applyCreate(newPaymentMethod: NewPaymentMethod): Promise<PaymentMethodModel> {
877875
const filteredValues = Object.fromEntries(
878876
Object.entries(newPaymentMethod).filter(([key]) =>
879-
!instance.guarded.includes(key) && instance.fillable.includes(key),
877+
!this.guarded.includes(key) && this.fillable.includes(key),
880878
),
881879
) as NewPaymentMethod
882880

@@ -886,14 +884,24 @@ export class PaymentMethodModel {
886884
.values(filteredValues)
887885
.executeTakeFirst()
888886

889-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as PaymentMethodModel
887+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as PaymentMethodModel
890888

891889
if (model)
892890
dispatch('paymentmethod:created', model)
893891

894892
return model
895893
}
896894

895+
async create(newPaymentMethod: NewPaymentMethod): Promise<PaymentMethodModel> {
896+
return await this.create(newPaymentMethod)
897+
}
898+
899+
static async create(newPaymentMethod: NewPaymentMethod): Promise<PaymentMethodModel> {
900+
const instance = new PaymentMethodModel(null)
901+
902+
return await instance.create(newPaymentMethod)
903+
}
904+
897905
static async createMany(newPaymentMethod: NewPaymentMethod[]): Promise<void> {
898906
const instance = new PaymentMethodModel(null)
899907

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,27 +809,35 @@ export class PostModel {
809809
return await instance.applyPaginate(options)
810810
}
811811

812-
static async create(newPost: NewPost): Promise<PostModel> {
813-
const instance = new PostModel(null)
814-
812+
async applyCreate(newPost: NewPost): Promise<PostModel> {
815813
const filteredValues = Object.fromEntries(
816814
Object.entries(newPost).filter(([key]) =>
817-
!instance.guarded.includes(key) && instance.fillable.includes(key),
815+
!this.guarded.includes(key) && this.fillable.includes(key),
818816
),
819817
) as NewPost
820818

821819
const result = await DB.instance.insertInto('posts')
822820
.values(filteredValues)
823821
.executeTakeFirst()
824822

825-
const model = await instance.find(Number(result.numInsertedOrUpdatedRows)) as PostModel
823+
const model = await this.find(Number(result.numInsertedOrUpdatedRows)) as PostModel
826824

827825
if (model)
828826
dispatch('post:created', model)
829827

830828
return model
831829
}
832830

831+
async create(newPost: NewPost): Promise<PostModel> {
832+
return await this.create(newPost)
833+
}
834+
835+
static async create(newPost: NewPost): Promise<PostModel> {
836+
const instance = new PostModel(null)
837+
838+
return await instance.create(newPost)
839+
}
840+
833841
static async createMany(newPost: NewPost[]): Promise<void> {
834842
const instance = new PostModel(null)
835843

0 commit comments

Comments
 (0)