Skip to content

Commit 2a95f62

Browse files
chore: wip
1 parent e054d59 commit 2a95f62

File tree

18 files changed

+450
-144
lines changed

18 files changed

+450
-144
lines changed

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,9 @@ export async function generateModelString(
15641564
}
15651565
15661566
whereColumn(first: string, operator: string, second: string): ${modelName}Model {
1567-
return ${modelName}Model.whereColumn(first, operator, second)
1567+
this.selectFromQuery = this.selectFromQuery.whereRef(first, operator, second)
1568+
1569+
return this
15681570
}
15691571
15701572
static whereColumn(first: string, operator: string, second: string): ${modelName}Model {
@@ -1576,21 +1578,30 @@ export async function generateModelString(
15761578
}
15771579
15781580
whereRef(column: string, ...args: string[]): ${modelName}Model {
1579-
return ${modelName}Model.whereRef(column, ...args)
1580-
}
1581-
1582-
static whereRef(column: string, ...args: string[]): ${modelName}Model {
15831581
const [operatorOrValue, value] = args
15841582
const operator = value === undefined ? '=' : operatorOrValue
15851583
const actualValue = value === undefined ? operatorOrValue : value
15861584
15871585
const instance = new ${modelName}Model(null)
15881586
instance.selectFromQuery = instance.selectFromQuery.whereRef(column, operator, actualValue)
1587+
15891588
return instance
15901589
}
1590+
1591+
whereRef(column: string, ...args: string[]): ${modelName}Model {
1592+
return this.whereRef(column, ...args)
1593+
}
1594+
1595+
static whereRef(column: string, ...args: string[]): ${modelName}Model {
1596+
const instance = new ${modelName}Model(null)
1597+
1598+
return instance.whereRef(column, ...args)
1599+
}
15911600
15921601
whereRaw(sqlStatement: string): ${modelName}Model {
1593-
return ${modelName}Model.whereRaw(sqlStatement)
1602+
this.selectFromQuery = this.selectFromQuery.where(sql\`\${sqlStatement}\`)
1603+
1604+
return this
15941605
}
15951606
15961607
static whereRaw(sqlStatement: string): ${modelName}Model {
@@ -2096,7 +2107,11 @@ export async function generateModelString(
20962107
${likeableStatements}
20972108
20982109
distinct(column: keyof ${modelName}Type): ${modelName}Model {
2099-
return ${modelName}Model.distinct(column)
2110+
this.selectFromQuery = this.selectFromQuery.select(column).distinct()
2111+
2112+
this.hasSelect = true
2113+
2114+
return this
21002115
}
21012116
21022117
static distinct(column: keyof ${modelName}Type): ${modelName}Model {
@@ -2110,7 +2125,9 @@ export async function generateModelString(
21102125
}
21112126
21122127
join(table: string, firstCol: string, secondCol: string): ${modelName}Model {
2113-
return ${modelName}Model.join(table, firstCol, secondCol)
2128+
this.selectFromQuery = this.selectFromQuery.innerJoin(table, firstCol, secondCol)
2129+
2130+
return this
21142131
}
21152132
21162133
static join(table: string, firstCol: string, secondCol: string): ${modelName}Model {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,9 @@ export class AccessTokenModel {
782782
}
783783

784784
whereColumn(first: string, operator: string, second: string): AccessTokenModel {
785-
return AccessTokenModel.whereColumn(first, operator, second)
785+
this.selectFromQuery = this.selectFromQuery.whereRef(first, operator, second)
786+
787+
return this
786788
}
787789

788790
static whereColumn(first: string, operator: string, second: string): AccessTokenModel {
@@ -794,21 +796,30 @@ export class AccessTokenModel {
794796
}
795797

796798
whereRef(column: string, ...args: string[]): AccessTokenModel {
797-
return AccessTokenModel.whereRef(column, ...args)
798-
}
799-
800-
static whereRef(column: string, ...args: string[]): AccessTokenModel {
801799
const [operatorOrValue, value] = args
802800
const operator = value === undefined ? '=' : operatorOrValue
803801
const actualValue = value === undefined ? operatorOrValue : value
804802

805803
const instance = new AccessTokenModel(null)
806804
instance.selectFromQuery = instance.selectFromQuery.whereRef(column, operator, actualValue)
805+
807806
return instance
808807
}
809808

809+
whereRef(column: string, ...args: string[]): AccessTokenModel {
810+
return this.whereRef(column, ...args)
811+
}
812+
813+
static whereRef(column: string, ...args: string[]): AccessTokenModel {
814+
const instance = new AccessTokenModel(null)
815+
816+
return instance.whereRef(column, ...args)
817+
}
818+
810819
whereRaw(sqlStatement: string): AccessTokenModel {
811-
return AccessTokenModel.whereRaw(sqlStatement)
820+
this.selectFromQuery = this.selectFromQuery.where(sql`${sqlStatement}`)
821+
822+
return this
812823
}
813824

814825
static whereRaw(sqlStatement: string): AccessTokenModel {
@@ -1341,7 +1352,11 @@ export class AccessTokenModel {
13411352
}
13421353

13431354
distinct(column: keyof AccessTokenType): AccessTokenModel {
1344-
return AccessTokenModel.distinct(column)
1355+
this.selectFromQuery = this.selectFromQuery.select(column).distinct()
1356+
1357+
this.hasSelect = true
1358+
1359+
return this
13451360
}
13461361

13471362
static distinct(column: keyof AccessTokenType): AccessTokenModel {
@@ -1355,7 +1370,9 @@ export class AccessTokenModel {
13551370
}
13561371

13571372
join(table: string, firstCol: string, secondCol: string): AccessTokenModel {
1358-
return AccessTokenModel.join(table, firstCol, secondCol)
1373+
this.selectFromQuery = this.selectFromQuery.innerJoin(table, firstCol, secondCol)
1374+
1375+
return this
13591376
}
13601377

13611378
static join(table: string, firstCol: string, secondCol: string): AccessTokenModel {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ export class ActivityModel {
812812
}
813813

814814
whereColumn(first: string, operator: string, second: string): ActivityModel {
815-
return ActivityModel.whereColumn(first, operator, second)
815+
this.selectFromQuery = this.selectFromQuery.whereRef(first, operator, second)
816+
817+
return this
816818
}
817819

818820
static whereColumn(first: string, operator: string, second: string): ActivityModel {
@@ -824,21 +826,30 @@ export class ActivityModel {
824826
}
825827

826828
whereRef(column: string, ...args: string[]): ActivityModel {
827-
return ActivityModel.whereRef(column, ...args)
828-
}
829-
830-
static whereRef(column: string, ...args: string[]): ActivityModel {
831829
const [operatorOrValue, value] = args
832830
const operator = value === undefined ? '=' : operatorOrValue
833831
const actualValue = value === undefined ? operatorOrValue : value
834832

835833
const instance = new ActivityModel(null)
836834
instance.selectFromQuery = instance.selectFromQuery.whereRef(column, operator, actualValue)
835+
837836
return instance
838837
}
839838

839+
whereRef(column: string, ...args: string[]): ActivityModel {
840+
return this.whereRef(column, ...args)
841+
}
842+
843+
static whereRef(column: string, ...args: string[]): ActivityModel {
844+
const instance = new ActivityModel(null)
845+
846+
return instance.whereRef(column, ...args)
847+
}
848+
840849
whereRaw(sqlStatement: string): ActivityModel {
841-
return ActivityModel.whereRaw(sqlStatement)
850+
this.selectFromQuery = this.selectFromQuery.where(sql`${sqlStatement}`)
851+
852+
return this
842853
}
843854

844855
static whereRaw(sqlStatement: string): ActivityModel {
@@ -1430,7 +1441,11 @@ export class ActivityModel {
14301441
}
14311442

14321443
distinct(column: keyof ActivityType): ActivityModel {
1433-
return ActivityModel.distinct(column)
1444+
this.selectFromQuery = this.selectFromQuery.select(column).distinct()
1445+
1446+
this.hasSelect = true
1447+
1448+
return this
14341449
}
14351450

14361451
static distinct(column: keyof ActivityType): ActivityModel {
@@ -1444,7 +1459,9 @@ export class ActivityModel {
14441459
}
14451460

14461461
join(table: string, firstCol: string, secondCol: string): ActivityModel {
1447-
return ActivityModel.join(table, firstCol, secondCol)
1462+
this.selectFromQuery = this.selectFromQuery.innerJoin(table, firstCol, secondCol)
1463+
1464+
return this
14481465
}
14491466

14501467
static join(table: string, firstCol: string, secondCol: string): ActivityModel {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ export class DeploymentModel {
823823
}
824824

825825
whereColumn(first: string, operator: string, second: string): DeploymentModel {
826-
return DeploymentModel.whereColumn(first, operator, second)
826+
this.selectFromQuery = this.selectFromQuery.whereRef(first, operator, second)
827+
828+
return this
827829
}
828830

829831
static whereColumn(first: string, operator: string, second: string): DeploymentModel {
@@ -835,21 +837,30 @@ export class DeploymentModel {
835837
}
836838

837839
whereRef(column: string, ...args: string[]): DeploymentModel {
838-
return DeploymentModel.whereRef(column, ...args)
839-
}
840-
841-
static whereRef(column: string, ...args: string[]): DeploymentModel {
842840
const [operatorOrValue, value] = args
843841
const operator = value === undefined ? '=' : operatorOrValue
844842
const actualValue = value === undefined ? operatorOrValue : value
845843

846844
const instance = new DeploymentModel(null)
847845
instance.selectFromQuery = instance.selectFromQuery.whereRef(column, operator, actualValue)
846+
848847
return instance
849848
}
850849

850+
whereRef(column: string, ...args: string[]): DeploymentModel {
851+
return this.whereRef(column, ...args)
852+
}
853+
854+
static whereRef(column: string, ...args: string[]): DeploymentModel {
855+
const instance = new DeploymentModel(null)
856+
857+
return instance.whereRef(column, ...args)
858+
}
859+
851860
whereRaw(sqlStatement: string): DeploymentModel {
852-
return DeploymentModel.whereRaw(sqlStatement)
861+
this.selectFromQuery = this.selectFromQuery.where(sql`${sqlStatement}`)
862+
863+
return this
853864
}
854865

855866
static whereRaw(sqlStatement: string): DeploymentModel {
@@ -1406,7 +1417,11 @@ export class DeploymentModel {
14061417
}
14071418

14081419
distinct(column: keyof DeploymentType): DeploymentModel {
1409-
return DeploymentModel.distinct(column)
1420+
this.selectFromQuery = this.selectFromQuery.select(column).distinct()
1421+
1422+
this.hasSelect = true
1423+
1424+
return this
14101425
}
14111426

14121427
static distinct(column: keyof DeploymentType): DeploymentModel {
@@ -1420,7 +1435,9 @@ export class DeploymentModel {
14201435
}
14211436

14221437
join(table: string, firstCol: string, secondCol: string): DeploymentModel {
1423-
return DeploymentModel.join(table, firstCol, secondCol)
1438+
this.selectFromQuery = this.selectFromQuery.innerJoin(table, firstCol, secondCol)
1439+
1440+
return this
14241441
}
14251442

14261443
static join(table: string, firstCol: string, secondCol: string): DeploymentModel {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,9 @@ export class ErrorModel {
774774
}
775775

776776
whereColumn(first: string, operator: string, second: string): ErrorModel {
777-
return ErrorModel.whereColumn(first, operator, second)
777+
this.selectFromQuery = this.selectFromQuery.whereRef(first, operator, second)
778+
779+
return this
778780
}
779781

780782
static whereColumn(first: string, operator: string, second: string): ErrorModel {
@@ -786,21 +788,30 @@ export class ErrorModel {
786788
}
787789

788790
whereRef(column: string, ...args: string[]): ErrorModel {
789-
return ErrorModel.whereRef(column, ...args)
790-
}
791-
792-
static whereRef(column: string, ...args: string[]): ErrorModel {
793791
const [operatorOrValue, value] = args
794792
const operator = value === undefined ? '=' : operatorOrValue
795793
const actualValue = value === undefined ? operatorOrValue : value
796794

797795
const instance = new ErrorModel(null)
798796
instance.selectFromQuery = instance.selectFromQuery.whereRef(column, operator, actualValue)
797+
799798
return instance
800799
}
801800

801+
whereRef(column: string, ...args: string[]): ErrorModel {
802+
return this.whereRef(column, ...args)
803+
}
804+
805+
static whereRef(column: string, ...args: string[]): ErrorModel {
806+
const instance = new ErrorModel(null)
807+
808+
return instance.whereRef(column, ...args)
809+
}
810+
802811
whereRaw(sqlStatement: string): ErrorModel {
803-
return ErrorModel.whereRaw(sqlStatement)
812+
this.selectFromQuery = this.selectFromQuery.where(sql`${sqlStatement}`)
813+
814+
return this
804815
}
805816

806817
static whereRaw(sqlStatement: string): ErrorModel {
@@ -1327,7 +1338,11 @@ export class ErrorModel {
13271338
}
13281339

13291340
distinct(column: keyof ErrorType): ErrorModel {
1330-
return ErrorModel.distinct(column)
1341+
this.selectFromQuery = this.selectFromQuery.select(column).distinct()
1342+
1343+
this.hasSelect = true
1344+
1345+
return this
13311346
}
13321347

13331348
static distinct(column: keyof ErrorType): ErrorModel {
@@ -1341,7 +1356,9 @@ export class ErrorModel {
13411356
}
13421357

13431358
join(table: string, firstCol: string, secondCol: string): ErrorModel {
1344-
return ErrorModel.join(table, firstCol, secondCol)
1359+
this.selectFromQuery = this.selectFromQuery.innerJoin(table, firstCol, secondCol)
1360+
1361+
return this
13451362
}
13461363

13471364
static join(table: string, firstCol: string, secondCol: string): ErrorModel {

0 commit comments

Comments
 (0)