Skip to content

Commit ed44c16

Browse files
chore: wip
1 parent 5f3b304 commit ed44c16

File tree

20 files changed

+1073
-972
lines changed

20 files changed

+1073
-972
lines changed

storage/framework/core/components/combobox/src/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ import {
66
ComboboxOptions,
77
} from '@headlessui/vue'
88

9-
109
export { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions }

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

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,15 +1163,19 @@ export async function generateModelString(
11631163
static async count(): Promise<number> {
11641164
const instance = new ${modelName}Model(null)
11651165
1166-
const result = instance.selectFromQuery
1166+
const result = await instance.selectFromQuery
11671167
.select(sql\`COUNT(*) as count\`)
11681168
.executeTakeFirst()
11691169
11701170
return result.count || 0
11711171
}
11721172
11731173
async count(): Promise<number> {
1174-
return ${modelName}Model.count()
1174+
const result = await this.selectFromQuery
1175+
.select(sql\`COUNT(*) as count\`)
1176+
.executeTakeFirst()
1177+
1178+
return result.count || 0
11751179
}
11761180
11771181
async max(field: keyof ${modelName}Model): Promise<number> {
@@ -1514,7 +1518,7 @@ export async function generateModelString(
15141518
.execute()
15151519
}
15161520
1517-
private static applyWhere(instance: ${modelName}Model, column: string, ...args: any[]): ${modelName}Model {
1521+
applyWhere(instance: ${modelName}Model, column: string, ...args: any[]): ${modelName}Model {
15181522
const [operatorOrValue, value] = args
15191523
const operator = value === undefined ? '=' : operatorOrValue
15201524
const actualValue = value === undefined ? operatorOrValue : value
@@ -1527,12 +1531,13 @@ export async function generateModelString(
15271531
}
15281532
15291533
where(column: string, ...args: any[]): ${modelName}Model {
1530-
return ${modelName}Model.applyWhere(this, column, ...args)
1534+
return this.applyWhere(this, column, ...args)
15311535
}
15321536
15331537
static where(column: string, ...args: any[]): ${modelName}Model {
15341538
const instance = new ${modelName}Model(null)
1535-
return ${modelName}Model.applyWhere(instance, column, ...args)
1539+
1540+
return instance.applyWhere(instance, column, ...args)
15361541
}
15371542
15381543
whereColumn(first: string, operator: string, second: string): ${modelName}Model {
@@ -1573,46 +1578,48 @@ export async function generateModelString(
15731578
return instance
15741579
}
15751580
1576-
orWhere(...conditions: (string | [string, any] | [string, string, any])[]): ${modelName}Model {
1577-
return ${modelName}Model.orWhere(...conditions)
1578-
}
1579-
1580-
static orWhere(...conditions: (string | [string, any] | [string, string, any])[]): ${modelName}Model {
1581-
const instance = new ${modelName}Model(null)
1581+
orWhere(...conditions: [string, any][]): ${modelName}Model {
1582+
this.selectFromQuery = this.selectFromQuery.where((eb) => {
1583+
return eb.or(
1584+
conditions.map(([column, value]) => eb(column, '=', value))
1585+
)
1586+
})
15821587
1583-
if (conditions.length === 0) {
1584-
throw new HttpError(500, "At least one condition must be provided")
1585-
}
1588+
this.updateFromQuery = this.updateFromQuery.where((eb) => {
1589+
return eb.or(
1590+
conditions.map(([column, value]) => eb(column, '=', value))
1591+
)
1592+
})
15861593
1587-
// Process conditions to handle different formats
1588-
const processedConditions = conditions.map(condition => {
1589-
if (Array.isArray(condition)) {
1590-
if (condition.length === 2) {
1591-
return [condition[0], '=', condition[1]]
1592-
}
1593-
return condition
1594-
}
1595-
throw new Error('Invalid condition format')
1594+
this.deleteFromQuery = this.deleteFromQuery.where((eb) => {
1595+
return eb.or(
1596+
conditions.map(([column, value]) => eb(column, '=', value))
1597+
)
15961598
})
15971599
1598-
// Use the expression builder to append the OR conditions
1599-
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1600-
eb.or(
1601-
processedConditions.map(([column, operator, value]) => eb(column, operator, value))
1600+
return this
1601+
}
1602+
1603+
static orWhere(...conditions: [string, any][]): ${modelName}Model {
1604+
const instance = new ${modelName}Model(null)
1605+
1606+
instance.selectFromQuery = instance.selectFromQuery.where((eb) => {
1607+
return eb.or(
1608+
conditions.map(([column, value]) => eb(column, '=', value))
16021609
)
1603-
)
1610+
})
16041611
1605-
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1606-
eb.or(
1607-
processedConditions.map(([column, operator, value]) => eb(column, operator, value))
1612+
instance.updateFromQuery = instance.updateFromQuery.where((eb) => {
1613+
return eb.or(
1614+
conditions.map(([column, value]) => eb(column, '=', value))
16081615
)
1609-
)
1616+
})
16101617
1611-
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1612-
eb.or(
1613-
processedConditions.map(([column, operator, value]) => eb(column, operator, value))
1618+
instance.deleteFromQuery = instance.deleteFromQuery.where((eb) => {
1619+
return eb.or(
1620+
conditions.map(([column, value]) => eb(column, '=', value))
16141621
)
1615-
)
1622+
})
16161623
16171624
return instance
16181625
}

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

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,19 @@ export class AccessTokenModel {
390390
static async count(): Promise<number> {
391391
const instance = new AccessTokenModel(null)
392392

393-
const result = instance.selectFromQuery
393+
const result = await instance.selectFromQuery
394394
.select(sql`COUNT(*) as count`)
395395
.executeTakeFirst()
396396

397397
return result.count || 0
398398
}
399399

400400
async count(): Promise<number> {
401-
return AccessTokenModel.count()
401+
const result = await this.selectFromQuery
402+
.select(sql`COUNT(*) as count`)
403+
.executeTakeFirst()
404+
405+
return result.count || 0
402406
}
403407

404408
async max(field: keyof AccessTokenModel): Promise<number> {
@@ -732,7 +736,7 @@ export class AccessTokenModel {
732736
.execute()
733737
}
734738

735-
private static applyWhere(instance: AccessTokenModel, column: string, ...args: any[]): AccessTokenModel {
739+
applyWhere(instance: AccessTokenModel, column: string, ...args: any[]): AccessTokenModel {
736740
const [operatorOrValue, value] = args
737741
const operator = value === undefined ? '=' : operatorOrValue
738742
const actualValue = value === undefined ? operatorOrValue : value
@@ -745,12 +749,13 @@ export class AccessTokenModel {
745749
}
746750

747751
where(column: string, ...args: any[]): AccessTokenModel {
748-
return AccessTokenModel.applyWhere(this, column, ...args)
752+
return this.applyWhere(this, column, ...args)
749753
}
750754

751755
static where(column: string, ...args: any[]): AccessTokenModel {
752756
const instance = new AccessTokenModel(null)
753-
return AccessTokenModel.applyWhere(instance, column, ...args)
757+
758+
return instance.applyWhere(instance, column, ...args)
754759
}
755760

756761
whereColumn(first: string, operator: string, second: string): AccessTokenModel {
@@ -791,45 +796,45 @@ export class AccessTokenModel {
791796
return instance
792797
}
793798

794-
orWhere(...conditions: (string | [string, any] | [string, string, any])[]): AccessTokenModel {
795-
return AccessTokenModel.orWhere(...conditions)
799+
orWhere(column: string, ...args: any[]): AccessTokenModel {
800+
const [operatorOrValue, value] = args
801+
const operator = value === undefined ? '=' : operatorOrValue
802+
const actualValue = value === undefined ? operatorOrValue : value
803+
804+
// Use the expression builder to append the OR condition
805+
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
806+
eb.or([eb(column, operator, actualValue)]),
807+
)
808+
809+
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
810+
eb.or([eb(column, operator, actualValue)]),
811+
)
812+
813+
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
814+
eb.or([eb(column, operator, actualValue)]),
815+
)
816+
817+
return this
796818
}
797819

798-
static orWhere(...conditions: (string | [string, any] | [string, string, any])[]): AccessTokenModel {
820+
static orWhere(column: string, ...args: any[]): AccessTokenModel {
799821
const instance = new AccessTokenModel(null)
800822

801-
if (conditions.length === 0) {
802-
throw new HttpError(500, 'At least one condition must be provided')
803-
}
804-
805-
// Process conditions to handle different formats
806-
const processedConditions = conditions.map((condition) => {
807-
if (Array.isArray(condition)) {
808-
if (condition.length === 2) {
809-
return [condition[0], '=', condition[1]]
810-
}
811-
return condition
812-
}
813-
throw new Error('Invalid condition format')
814-
})
823+
const [operatorOrValue, value] = args
824+
const operator = value === undefined ? '=' : operatorOrValue
825+
const actualValue = value === undefined ? operatorOrValue : value
815826

816-
// Use the expression builder to append the OR conditions
827+
// Use the expression builder to append the OR condition
817828
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
818-
eb.or(
819-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
820-
),
829+
eb.or([eb(column, operator, actualValue)]),
821830
)
822831

823832
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
824-
eb.or(
825-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
826-
),
833+
eb.or([eb(column, operator, actualValue)]),
827834
)
828835

829836
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
830-
eb.or(
831-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
832-
),
837+
eb.or([eb(column, operator, actualValue)]),
833838
)
834839

835840
return instance

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

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,19 @@ export class ActivityModel {
409409
static async count(): Promise<number> {
410410
const instance = new ActivityModel(null)
411411

412-
const result = instance.selectFromQuery
412+
const result = await instance.selectFromQuery
413413
.select(sql`COUNT(*) as count`)
414414
.executeTakeFirst()
415415

416416
return result.count || 0
417417
}
418418

419419
async count(): Promise<number> {
420-
return ActivityModel.count()
420+
const result = await this.selectFromQuery
421+
.select(sql`COUNT(*) as count`)
422+
.executeTakeFirst()
423+
424+
return result.count || 0
421425
}
422426

423427
async max(field: keyof ActivityModel): Promise<number> {
@@ -762,7 +766,7 @@ export class ActivityModel {
762766
.execute()
763767
}
764768

765-
private static applyWhere(instance: ActivityModel, column: string, ...args: any[]): ActivityModel {
769+
applyWhere(instance: ActivityModel, column: string, ...args: any[]): ActivityModel {
766770
const [operatorOrValue, value] = args
767771
const operator = value === undefined ? '=' : operatorOrValue
768772
const actualValue = value === undefined ? operatorOrValue : value
@@ -775,12 +779,13 @@ export class ActivityModel {
775779
}
776780

777781
where(column: string, ...args: any[]): ActivityModel {
778-
return ActivityModel.applyWhere(this, column, ...args)
782+
return this.applyWhere(this, column, ...args)
779783
}
780784

781785
static where(column: string, ...args: any[]): ActivityModel {
782786
const instance = new ActivityModel(null)
783-
return ActivityModel.applyWhere(instance, column, ...args)
787+
788+
return instance.applyWhere(instance, column, ...args)
784789
}
785790

786791
whereColumn(first: string, operator: string, second: string): ActivityModel {
@@ -821,45 +826,45 @@ export class ActivityModel {
821826
return instance
822827
}
823828

824-
orWhere(...conditions: (string | [string, any] | [string, string, any])[]): ActivityModel {
825-
return ActivityModel.orWhere(...conditions)
829+
orWhere(column: string, ...args: any[]): ActivityModel {
830+
const [operatorOrValue, value] = args
831+
const operator = value === undefined ? '=' : operatorOrValue
832+
const actualValue = value === undefined ? operatorOrValue : value
833+
834+
// Use the expression builder to append the OR condition
835+
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
836+
eb.or([eb(column, operator, actualValue)]),
837+
)
838+
839+
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
840+
eb.or([eb(column, operator, actualValue)]),
841+
)
842+
843+
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
844+
eb.or([eb(column, operator, actualValue)]),
845+
)
846+
847+
return this
826848
}
827849

828-
static orWhere(...conditions: (string | [string, any] | [string, string, any])[]): ActivityModel {
850+
static orWhere(column: string, ...args: any[]): ActivityModel {
829851
const instance = new ActivityModel(null)
830852

831-
if (conditions.length === 0) {
832-
throw new HttpError(500, 'At least one condition must be provided')
833-
}
834-
835-
// Process conditions to handle different formats
836-
const processedConditions = conditions.map((condition) => {
837-
if (Array.isArray(condition)) {
838-
if (condition.length === 2) {
839-
return [condition[0], '=', condition[1]]
840-
}
841-
return condition
842-
}
843-
throw new Error('Invalid condition format')
844-
})
853+
const [operatorOrValue, value] = args
854+
const operator = value === undefined ? '=' : operatorOrValue
855+
const actualValue = value === undefined ? operatorOrValue : value
845856

846-
// Use the expression builder to append the OR conditions
857+
// Use the expression builder to append the OR condition
847858
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
848-
eb.or(
849-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
850-
),
859+
eb.or([eb(column, operator, actualValue)]),
851860
)
852861

853862
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
854-
eb.or(
855-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
856-
),
863+
eb.or([eb(column, operator, actualValue)]),
857864
)
858865

859866
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
860-
eb.or(
861-
processedConditions.map(([column, operator, value]) => eb(column, operator, value)),
862-
),
867+
eb.or([eb(column, operator, actualValue)]),
863868
)
864869

865870
return instance

0 commit comments

Comments
 (0)