@@ -2,7 +2,7 @@ import type { Insertable, RawBuilder, Selectable, Updateable } from '@stacksjs/d
2
2
import type { UserModel } from './User'
3
3
import { randomUUIDv7 } from 'bun'
4
4
import { cache } from '@stacksjs/cache'
5
- import { db , sql } from '@stacksjs/database'
5
+ import { sql } from '@stacksjs/database'
6
6
import { HttpError , ModelNotFoundException } from '@stacksjs/error-handling'
7
7
import { dispatch } from '@stacksjs/events'
8
8
import { DB , SubqueryBuilder } from '@stacksjs/orm'
@@ -135,7 +135,7 @@ export class DeploymentModel {
135
135
136
136
// Method to find a Deployment by ID
137
137
static async find ( id : number ) : Promise < DeploymentModel | undefined > {
138
- const model = await db . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
138
+ const model = await DB . instance . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
139
139
140
140
if ( ! model )
141
141
return undefined
@@ -156,7 +156,7 @@ export class DeploymentModel {
156
156
}
157
157
158
158
static async first ( ) : Promise < DeploymentModel | undefined > {
159
- const model = await db . selectFrom ( 'deployments' )
159
+ const model = await DB . instance . selectFrom ( 'deployments' )
160
160
. selectAll ( )
161
161
. executeTakeFirst ( )
162
162
@@ -200,7 +200,7 @@ export class DeploymentModel {
200
200
}
201
201
202
202
static async all ( ) : Promise < DeploymentModel [ ] > {
203
- const models = await db . selectFrom ( 'deployments' ) . selectAll ( ) . execute ( )
203
+ const models = await DB . instance . selectFrom ( 'deployments' ) . selectAll ( ) . execute ( )
204
204
205
205
const data = await Promise . all ( models . map ( async ( model : DeploymentType ) => {
206
206
const instance = new DeploymentModel ( model )
@@ -218,7 +218,7 @@ export class DeploymentModel {
218
218
}
219
219
220
220
static async findOrFail ( id : number ) : Promise < DeploymentModel > {
221
- const model = await db . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
221
+ const model = await DB . instance . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
222
222
223
223
const instance = new DeploymentModel ( null )
224
224
@@ -235,7 +235,7 @@ export class DeploymentModel {
235
235
}
236
236
237
237
static async findMany ( ids : number [ ] ) : Promise < DeploymentModel [ ] > {
238
- let query = db . selectFrom ( 'deployments' ) . where ( 'id' , 'in' , ids )
238
+ let query = DB . instance . selectFrom ( 'deployments' ) . where ( 'id' , 'in' , ids )
239
239
240
240
const instance = new DeploymentModel ( null )
241
241
@@ -531,14 +531,14 @@ export class DeploymentModel {
531
531
532
532
// Method to get all deployments
533
533
static async paginate ( options : QueryOptions = { limit : 10 , offset : 0 , page : 1 } ) : Promise < DeploymentResponse > {
534
- const totalRecordsResult = await db . selectFrom ( 'deployments' )
534
+ const totalRecordsResult = await DB . instance . selectFrom ( 'deployments' )
535
535
. select ( db . fn . count ( 'id' ) . as ( 'total' ) ) // Use 'id' or another actual column name
536
536
. executeTakeFirst ( )
537
537
538
538
const totalRecords = Number ( totalRecordsResult ?. total ) || 0
539
539
const totalPages = Math . ceil ( totalRecords / ( options . limit ?? 10 ) )
540
540
541
- const deploymentsWithExtra = await db . selectFrom ( 'deployments' )
541
+ const deploymentsWithExtra = await DB . instance . selectFrom ( 'deployments' )
542
542
. selectAll ( )
543
543
. orderBy ( 'id' , 'asc' ) // Assuming 'id' is used for cursor-based pagination
544
544
. limit ( ( options . limit ?? 10 ) + 1 ) // Fetch one extra record
@@ -834,7 +834,7 @@ export class DeploymentModel {
834
834
}
835
835
836
836
static async latest ( ) : Promise < DeploymentType | undefined > {
837
- const model = await db . selectFrom ( 'deployments' )
837
+ const model = await DB . instance . selectFrom ( 'deployments' )
838
838
. selectAll ( )
839
839
. orderBy ( 'created_at' , 'desc' )
840
840
. executeTakeFirst ( )
@@ -850,7 +850,7 @@ export class DeploymentModel {
850
850
}
851
851
852
852
static async oldest ( ) : Promise < DeploymentType | undefined > {
853
- const model = await db . selectFrom ( 'deployments' )
853
+ const model = await DB . instance . selectFrom ( 'deployments' )
854
854
. selectAll ( )
855
855
. orderBy ( 'created_at' , 'asc' )
856
856
. executeTakeFirst ( )
@@ -879,7 +879,7 @@ export class DeploymentModel {
879
879
const value = condition [ key ]
880
880
881
881
// Attempt to find the first record matching the condition
882
- const existingDeployment = await db . selectFrom ( 'deployments' )
882
+ const existingDeployment = await DB . instance . selectFrom ( 'deployments' )
883
883
. selectAll ( )
884
884
. where ( key , '=' , value )
885
885
. executeTakeFirst ( )
@@ -907,7 +907,7 @@ export class DeploymentModel {
907
907
const value = condition [ key ]
908
908
909
909
// Attempt to find the first record matching the condition
910
- const existingDeployment = await db . selectFrom ( 'deployments' )
910
+ const existingDeployment = await DB . instance . selectFrom ( 'deployments' )
911
911
. selectAll ( )
912
912
. where ( key , '=' , value )
913
913
. executeTakeFirst ( )
@@ -920,7 +920,7 @@ export class DeploymentModel {
920
920
. executeTakeFirstOrThrow ( )
921
921
922
922
// Fetch and return the updated record
923
- const updatedDeployment = await db . selectFrom ( 'deployments' )
923
+ const updatedDeployment = await DB . instance . selectFrom ( 'deployments' )
924
924
. selectAll ( )
925
925
. where ( key , '=' , value )
926
926
. executeTakeFirst ( )
@@ -952,14 +952,14 @@ export class DeploymentModel {
952
952
}
953
953
954
954
async last ( ) : Promise < DeploymentType | undefined > {
955
- return await db . selectFrom ( 'deployments' )
955
+ return await DB . instance . selectFrom ( 'deployments' )
956
956
. selectAll ( )
957
957
. orderBy ( 'id' , 'desc' )
958
958
. executeTakeFirst ( )
959
959
}
960
960
961
961
static async last ( ) : Promise < DeploymentType | undefined > {
962
- const model = await db . selectFrom ( 'deployments' ) . selectAll ( ) . orderBy ( 'id' , 'desc' ) . executeTakeFirst ( )
962
+ const model = await DB . instance . selectFrom ( 'deployments' ) . selectAll ( ) . orderBy ( 'id' , 'desc' ) . executeTakeFirst ( )
963
963
964
964
if ( ! model )
965
965
return undefined
@@ -1187,7 +1187,7 @@ export class DeploymentModel {
1187
1187
}
1188
1188
1189
1189
async function find ( id : number ) : Promise < DeploymentModel | undefined > {
1190
- const query = db . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( )
1190
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( )
1191
1191
1192
1192
const model = await query . executeTakeFirst ( )
1193
1193
@@ -1222,49 +1222,49 @@ export async function remove(id: number): Promise<void> {
1222
1222
}
1223
1223
1224
1224
export async function whereCommitSha ( value : string ) : Promise < DeploymentModel [ ] > {
1225
- const query = db . selectFrom ( 'deployments' ) . where ( 'commit_sha' , '=' , value )
1225
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'commit_sha' , '=' , value )
1226
1226
const results = await query . execute ( )
1227
1227
1228
1228
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1229
1229
}
1230
1230
1231
1231
export async function whereCommitMessage ( value : string ) : Promise < DeploymentModel [ ] > {
1232
- const query = db . selectFrom ( 'deployments' ) . where ( 'commit_message' , '=' , value )
1232
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'commit_message' , '=' , value )
1233
1233
const results = await query . execute ( )
1234
1234
1235
1235
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1236
1236
}
1237
1237
1238
1238
export async function whereBranch ( value : string ) : Promise < DeploymentModel [ ] > {
1239
- const query = db . selectFrom ( 'deployments' ) . where ( 'branch' , '=' , value )
1239
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'branch' , '=' , value )
1240
1240
const results = await query . execute ( )
1241
1241
1242
1242
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1243
1243
}
1244
1244
1245
1245
export async function whereStatus ( value : string ) : Promise < DeploymentModel [ ] > {
1246
- const query = db . selectFrom ( 'deployments' ) . where ( 'status' , '=' , value )
1246
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'status' , '=' , value )
1247
1247
const results = await query . execute ( )
1248
1248
1249
1249
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1250
1250
}
1251
1251
1252
1252
export async function whereExecutionTime ( value : number ) : Promise < DeploymentModel [ ] > {
1253
- const query = db . selectFrom ( 'deployments' ) . where ( 'execution_time' , '=' , value )
1253
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'execution_time' , '=' , value )
1254
1254
const results = await query . execute ( )
1255
1255
1256
1256
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1257
1257
}
1258
1258
1259
1259
export async function whereDeployScript ( value : string ) : Promise < DeploymentModel [ ] > {
1260
- const query = db . selectFrom ( 'deployments' ) . where ( 'deploy_script' , '=' , value )
1260
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'deploy_script' , '=' , value )
1261
1261
const results = await query . execute ( )
1262
1262
1263
1263
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
1264
1264
}
1265
1265
1266
1266
export async function whereTerminalOutput ( value : string ) : Promise < DeploymentModel [ ] > {
1267
- const query = db . selectFrom ( 'deployments' ) . where ( 'terminal_output' , '=' , value )
1267
+ const query = DB . instance . selectFrom ( 'deployments' ) . where ( 'terminal_output' , '=' , value )
1268
1268
const results = await query . execute ( )
1269
1269
1270
1270
return results . map ( modelItem => new DeploymentModel ( modelItem ) )
0 commit comments