Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Feb 5, 2025
1 parent f567483 commit 29406ca
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 144 deletions.
20 changes: 12 additions & 8 deletions storage/framework/core/orm/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,26 +997,30 @@ export async function generateModelString(
return await instance.applyFind(id)
}
async first(): Promise<${modelName}Model | undefined> {
return await ${modelName}Model.first()
}
static async first(): Promise<${modelName}Model | undefined> {
async applyFirst(): Promise<${modelName}Model | undefined> {
const model = await DB.instance.selectFrom('${tableName}')
.selectAll()
.executeTakeFirst()
if (! model)
return undefined
const instance = new ${modelName}Model(null)
const result = await instance.mapWith(model)
const result = await this.mapWith(model)
const data = new ${modelName}Model(result as ${modelName}Type)
return data
}
async first(): Promise<${modelName}Model | undefined> {
return await this.first()
}
static async first(): Promise<${modelName}Model | undefined> {
const instance = new ${modelName}Model(null)
return await instance.first()
}
async firstOrFail(): Promise<${modelName}Model | undefined> {
return await ${modelName}Model.firstOrFail()
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/AccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,31 @@ export class AccessTokenModel {
return await instance.applyFind(id)
}

async first(): Promise<AccessTokenModel | undefined> {
return await AccessTokenModel.first()
}

static async first(): Promise<AccessTokenModel | undefined> {
async applyFirst(): Promise<AccessTokenModel | undefined> {
const model = await DB.instance.selectFrom('personal_access_tokens')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new AccessTokenModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new AccessTokenModel(result as AccessTokenType)

return data
}

async first(): Promise<AccessTokenModel | undefined> {
return await this.first()
}

static async first(): Promise<AccessTokenModel | undefined> {
const instance = new AccessTokenModel(null)

return await instance.first()
}

async firstOrFail(): Promise<AccessTokenModel | undefined> {
return await AccessTokenModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,31 @@ export class ActivityModel {
return await instance.applyFind(id)
}

async first(): Promise<ActivityModel | undefined> {
return await ActivityModel.first()
}

static async first(): Promise<ActivityModel | undefined> {
async applyFirst(): Promise<ActivityModel | undefined> {
const model = await DB.instance.selectFrom('activities')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new ActivityModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ActivityModel(result as ActivityType)

return data
}

async first(): Promise<ActivityModel | undefined> {
return await this.first()
}

static async first(): Promise<ActivityModel | undefined> {
const instance = new ActivityModel(null)

return await instance.first()
}

async firstOrFail(): Promise<ActivityModel | undefined> {
return await ActivityModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,31 @@ export class DeploymentModel {
return await instance.applyFind(id)
}

async first(): Promise<DeploymentModel | undefined> {
return await DeploymentModel.first()
}

static async first(): Promise<DeploymentModel | undefined> {
async applyFirst(): Promise<DeploymentModel | undefined> {
const model = await DB.instance.selectFrom('deployments')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new DeploymentModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new DeploymentModel(result as DeploymentType)

return data
}

async first(): Promise<DeploymentModel | undefined> {
return await this.first()
}

static async first(): Promise<DeploymentModel | undefined> {
const instance = new DeploymentModel(null)

return await instance.first()
}

async firstOrFail(): Promise<DeploymentModel | undefined> {
return await DeploymentModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,31 @@ export class ErrorModel {
return await instance.applyFind(id)
}

async first(): Promise<ErrorModel | undefined> {
return await ErrorModel.first()
}

static async first(): Promise<ErrorModel | undefined> {
async applyFirst(): Promise<ErrorModel | undefined> {
const model = await DB.instance.selectFrom('errors')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new ErrorModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ErrorModel(result as ErrorType)

return data
}

async first(): Promise<ErrorModel | undefined> {
return await this.first()
}

static async first(): Promise<ErrorModel | undefined> {
const instance = new ErrorModel(null)

return await instance.first()
}

async firstOrFail(): Promise<ErrorModel | undefined> {
return await ErrorModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/FailedJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,31 @@ export class FailedJobModel {
return await instance.applyFind(id)
}

async first(): Promise<FailedJobModel | undefined> {
return await FailedJobModel.first()
}

static async first(): Promise<FailedJobModel | undefined> {
async applyFirst(): Promise<FailedJobModel | undefined> {
const model = await DB.instance.selectFrom('failed_jobs')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new FailedJobModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new FailedJobModel(result as FailedJobType)

return data
}

async first(): Promise<FailedJobModel | undefined> {
return await this.first()
}

static async first(): Promise<FailedJobModel | undefined> {
const instance = new FailedJobModel(null)

return await instance.first()
}

async firstOrFail(): Promise<FailedJobModel | undefined> {
return await FailedJobModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,31 @@ export class JobModel {
return await instance.applyFind(id)
}

async first(): Promise<JobModel | undefined> {
return await JobModel.first()
}

static async first(): Promise<JobModel | undefined> {
async applyFirst(): Promise<JobModel | undefined> {
const model = await DB.instance.selectFrom('jobs')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new JobModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new JobModel(result as JobType)

return data
}

async first(): Promise<JobModel | undefined> {
return await this.first()
}

static async first(): Promise<JobModel | undefined> {
const instance = new JobModel(null)

return await instance.first()
}

async firstOrFail(): Promise<JobModel | undefined> {
return await JobModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/PaymentMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,31 @@ export class PaymentMethodModel {
return await instance.applyFind(id)
}

async first(): Promise<PaymentMethodModel | undefined> {
return await PaymentMethodModel.first()
}

static async first(): Promise<PaymentMethodModel | undefined> {
async applyFirst(): Promise<PaymentMethodModel | undefined> {
const model = await DB.instance.selectFrom('payment_methods')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new PaymentMethodModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new PaymentMethodModel(result as PaymentMethodType)

return data
}

async first(): Promise<PaymentMethodModel | undefined> {
return await this.first()
}

static async first(): Promise<PaymentMethodModel | undefined> {
const instance = new PaymentMethodModel(null)

return await instance.first()
}

async firstOrFail(): Promise<PaymentMethodModel | undefined> {
return await PaymentMethodModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,31 @@ export class PostModel {
return await instance.applyFind(id)
}

async first(): Promise<PostModel | undefined> {
return await PostModel.first()
}

static async first(): Promise<PostModel | undefined> {
async applyFirst(): Promise<PostModel | undefined> {
const model = await DB.instance.selectFrom('posts')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new PostModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new PostModel(result as PostType)

return data
}

async first(): Promise<PostModel | undefined> {
return await this.first()
}

static async first(): Promise<PostModel | undefined> {
const instance = new PostModel(null)

return await instance.first()
}

async firstOrFail(): Promise<PostModel | undefined> {
return await PostModel.firstOrFail()
}
Expand Down
20 changes: 12 additions & 8 deletions storage/framework/orm/src/models/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,31 @@ export class ProductModel {
return await instance.applyFind(id)
}

async first(): Promise<ProductModel | undefined> {
return await ProductModel.first()
}

static async first(): Promise<ProductModel | undefined> {
async applyFirst(): Promise<ProductModel | undefined> {
const model = await DB.instance.selectFrom('products')
.selectAll()
.executeTakeFirst()

if (!model)
return undefined

const instance = new ProductModel(null)

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ProductModel(result as ProductType)

return data
}

async first(): Promise<ProductModel | undefined> {
return await this.first()
}

static async first(): Promise<ProductModel | undefined> {
const instance = new ProductModel(null)

return await instance.first()
}

async firstOrFail(): Promise<ProductModel | undefined> {
return await ProductModel.firstOrFail()
}
Expand Down
Loading

0 comments on commit 29406ca

Please sign in to comment.