Skip to content

Commit 52dbfc6

Browse files
chore: wip
1 parent ac80eec commit 52dbfc6

File tree

17 files changed

+843
-0
lines changed

17 files changed

+843
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,57 @@ export async function generateModelString(
19041904
return results.length
19051905
}
19061906
1907+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<${modelName}Response> {
1908+
const totalRecordsResult = await db.selectFrom('${tableName}')
1909+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
1910+
.executeTakeFirst()
1911+
1912+
const totalRecords = Number(totalRecordsResult?.total) || 0
1913+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
1914+
1915+
if (this.hasSelect) {
1916+
${thisSoftDeleteStatements}
1917+
1918+
const ${tableName}WithExtra = await this.selectFromQuery.orderBy('id', 'asc')
1919+
.limit((options.limit ?? 10) + 1)
1920+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
1921+
.execute()
1922+
1923+
let nextCursor = null
1924+
if (${tableName}WithExtra.length > (options.limit ?? 10)) nextCursor = ${tableName}WithExtra.pop()?.id ?? null
1925+
1926+
return {
1927+
data: ${tableName}WithExtra,
1928+
paging: {
1929+
total_records: totalRecords,
1930+
page: options.page || 1,
1931+
total_pages: totalPages,
1932+
},
1933+
next_cursor: nextCursor,
1934+
}
1935+
}
1936+
1937+
${thisSoftDeleteStatements}
1938+
1939+
const ${tableName}WithExtra = await this.selectFromQuery.orderBy('id', 'asc')
1940+
.limit((options.limit ?? 10) + 1)
1941+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
1942+
.execute()
1943+
1944+
let nextCursor = null
1945+
if (${tableName}WithExtra.length > (options.limit ?? 10)) nextCursor = ${tableName}WithExtra.pop()?.id ?? null
1946+
1947+
return {
1948+
data: ${tableName}WithExtra,
1949+
paging: {
1950+
total_records: totalRecords,
1951+
page: options.page || 1,
1952+
total_pages: totalPages,
1953+
},
1954+
next_cursor: nextCursor,
1955+
}
1956+
}
1957+
19071958
// Method to get all ${tableName}
19081959
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<${modelName}Response> {
19091960
const totalRecordsResult = await db.selectFrom('${tableName}')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,55 @@ export class AccessTokenModel {
247247
return results.length
248248
}
249249

250+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<AccessTokenResponse> {
251+
const totalRecordsResult = await db.selectFrom('personal_access_tokens')
252+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
253+
.executeTakeFirst()
254+
255+
const totalRecords = Number(totalRecordsResult?.total) || 0
256+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
257+
258+
if (this.hasSelect) {
259+
const personal_access_tokensWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
260+
.limit((options.limit ?? 10) + 1)
261+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
262+
.execute()
263+
264+
let nextCursor = null
265+
if (personal_access_tokensWithExtra.length > (options.limit ?? 10))
266+
nextCursor = personal_access_tokensWithExtra.pop()?.id ?? null
267+
268+
return {
269+
data: personal_access_tokensWithExtra,
270+
paging: {
271+
total_records: totalRecords,
272+
page: options.page || 1,
273+
total_pages: totalPages,
274+
},
275+
next_cursor: nextCursor,
276+
}
277+
}
278+
279+
const personal_access_tokensWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
280+
.limit((options.limit ?? 10) + 1)
281+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
282+
.execute()
283+
284+
let nextCursor = null
285+
if (personal_access_tokensWithExtra.length > (options.limit ?? 10))
286+
nextCursor = personal_access_tokensWithExtra.pop()?.id ?? null
287+
288+
return {
289+
data: personal_access_tokensWithExtra,
290+
paging: {
291+
total_records: totalRecords,
292+
page: options.page || 1,
293+
total_pages: totalPages,
294+
},
295+
next_cursor: nextCursor,
296+
}
297+
}
298+
250299
// Method to get all personal_access_tokens
251300
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<AccessTokenResponse> {
252301
const totalRecordsResult = await db.selectFrom('personal_access_tokens')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,55 @@ export class DeploymentModel {
260260
return results.length
261261
}
262262

263+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<DeploymentResponse> {
264+
const totalRecordsResult = await db.selectFrom('deployments')
265+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
266+
.executeTakeFirst()
267+
268+
const totalRecords = Number(totalRecordsResult?.total) || 0
269+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
270+
271+
if (this.hasSelect) {
272+
const deploymentsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
273+
.limit((options.limit ?? 10) + 1)
274+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
275+
.execute()
276+
277+
let nextCursor = null
278+
if (deploymentsWithExtra.length > (options.limit ?? 10))
279+
nextCursor = deploymentsWithExtra.pop()?.id ?? null
280+
281+
return {
282+
data: deploymentsWithExtra,
283+
paging: {
284+
total_records: totalRecords,
285+
page: options.page || 1,
286+
total_pages: totalPages,
287+
},
288+
next_cursor: nextCursor,
289+
}
290+
}
291+
292+
const deploymentsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
293+
.limit((options.limit ?? 10) + 1)
294+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
295+
.execute()
296+
297+
let nextCursor = null
298+
if (deploymentsWithExtra.length > (options.limit ?? 10))
299+
nextCursor = deploymentsWithExtra.pop()?.id ?? null
300+
301+
return {
302+
data: deploymentsWithExtra,
303+
paging: {
304+
total_records: totalRecords,
305+
page: options.page || 1,
306+
total_pages: totalPages,
307+
},
308+
next_cursor: nextCursor,
309+
}
310+
}
311+
263312
// Method to get all deployments
264313
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<DeploymentResponse> {
265314
const totalRecordsResult = await db.selectFrom('deployments')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,55 @@ export class ErrorModel {
237237
return results.length
238238
}
239239

240+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<ErrorResponse> {
241+
const totalRecordsResult = await db.selectFrom('errors')
242+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
243+
.executeTakeFirst()
244+
245+
const totalRecords = Number(totalRecordsResult?.total) || 0
246+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
247+
248+
if (this.hasSelect) {
249+
const errorsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
250+
.limit((options.limit ?? 10) + 1)
251+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
252+
.execute()
253+
254+
let nextCursor = null
255+
if (errorsWithExtra.length > (options.limit ?? 10))
256+
nextCursor = errorsWithExtra.pop()?.id ?? null
257+
258+
return {
259+
data: errorsWithExtra,
260+
paging: {
261+
total_records: totalRecords,
262+
page: options.page || 1,
263+
total_pages: totalPages,
264+
},
265+
next_cursor: nextCursor,
266+
}
267+
}
268+
269+
const errorsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
270+
.limit((options.limit ?? 10) + 1)
271+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
272+
.execute()
273+
274+
let nextCursor = null
275+
if (errorsWithExtra.length > (options.limit ?? 10))
276+
nextCursor = errorsWithExtra.pop()?.id ?? null
277+
278+
return {
279+
data: errorsWithExtra,
280+
paging: {
281+
total_records: totalRecords,
282+
page: options.page || 1,
283+
total_pages: totalPages,
284+
},
285+
next_cursor: nextCursor,
286+
}
287+
}
288+
240289
// Method to get all errors
241290
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<ErrorResponse> {
242291
const totalRecordsResult = await db.selectFrom('errors')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,55 @@ export class FailedJobModel {
237237
return results.length
238238
}
239239

240+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<FailedJobResponse> {
241+
const totalRecordsResult = await db.selectFrom('failed_jobs')
242+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
243+
.executeTakeFirst()
244+
245+
const totalRecords = Number(totalRecordsResult?.total) || 0
246+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
247+
248+
if (this.hasSelect) {
249+
const failed_jobsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
250+
.limit((options.limit ?? 10) + 1)
251+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
252+
.execute()
253+
254+
let nextCursor = null
255+
if (failed_jobsWithExtra.length > (options.limit ?? 10))
256+
nextCursor = failed_jobsWithExtra.pop()?.id ?? null
257+
258+
return {
259+
data: failed_jobsWithExtra,
260+
paging: {
261+
total_records: totalRecords,
262+
page: options.page || 1,
263+
total_pages: totalPages,
264+
},
265+
next_cursor: nextCursor,
266+
}
267+
}
268+
269+
const failed_jobsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
270+
.limit((options.limit ?? 10) + 1)
271+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
272+
.execute()
273+
274+
let nextCursor = null
275+
if (failed_jobsWithExtra.length > (options.limit ?? 10))
276+
nextCursor = failed_jobsWithExtra.pop()?.id ?? null
277+
278+
return {
279+
data: failed_jobsWithExtra,
280+
paging: {
281+
total_records: totalRecords,
282+
page: options.page || 1,
283+
total_pages: totalPages,
284+
},
285+
next_cursor: nextCursor,
286+
}
287+
}
288+
240289
// Method to get all failed_jobs
241290
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<FailedJobResponse> {
242291
const totalRecordsResult = await db.selectFrom('failed_jobs')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,55 @@ export class JobModel {
237237
return results.length
238238
}
239239

240+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<JobResponse> {
241+
const totalRecordsResult = await db.selectFrom('jobs')
242+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
243+
.executeTakeFirst()
244+
245+
const totalRecords = Number(totalRecordsResult?.total) || 0
246+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
247+
248+
if (this.hasSelect) {
249+
const jobsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
250+
.limit((options.limit ?? 10) + 1)
251+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
252+
.execute()
253+
254+
let nextCursor = null
255+
if (jobsWithExtra.length > (options.limit ?? 10))
256+
nextCursor = jobsWithExtra.pop()?.id ?? null
257+
258+
return {
259+
data: jobsWithExtra,
260+
paging: {
261+
total_records: totalRecords,
262+
page: options.page || 1,
263+
total_pages: totalPages,
264+
},
265+
next_cursor: nextCursor,
266+
}
267+
}
268+
269+
const jobsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
270+
.limit((options.limit ?? 10) + 1)
271+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
272+
.execute()
273+
274+
let nextCursor = null
275+
if (jobsWithExtra.length > (options.limit ?? 10))
276+
nextCursor = jobsWithExtra.pop()?.id ?? null
277+
278+
return {
279+
data: jobsWithExtra,
280+
paging: {
281+
total_records: totalRecords,
282+
page: options.page || 1,
283+
total_pages: totalPages,
284+
},
285+
next_cursor: nextCursor,
286+
}
287+
}
288+
240289
// Method to get all jobs
241290
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<JobResponse> {
242291
const totalRecordsResult = await db.selectFrom('jobs')

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,55 @@ export class PaymentMethodModel {
270270
return results.length
271271
}
272272

273+
async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<PaymentMethodResponse> {
274+
const totalRecordsResult = await db.selectFrom('payment_methods')
275+
.select(db.fn.count('id').as('total')) // Use 'id' or another actual column name
276+
.executeTakeFirst()
277+
278+
const totalRecords = Number(totalRecordsResult?.total) || 0
279+
const totalPages = Math.ceil(totalRecords / (options.limit ?? 10))
280+
281+
if (this.hasSelect) {
282+
const payment_methodsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
283+
.limit((options.limit ?? 10) + 1)
284+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
285+
.execute()
286+
287+
let nextCursor = null
288+
if (payment_methodsWithExtra.length > (options.limit ?? 10))
289+
nextCursor = payment_methodsWithExtra.pop()?.id ?? null
290+
291+
return {
292+
data: payment_methodsWithExtra,
293+
paging: {
294+
total_records: totalRecords,
295+
page: options.page || 1,
296+
total_pages: totalPages,
297+
},
298+
next_cursor: nextCursor,
299+
}
300+
}
301+
302+
const payment_methodsWithExtra = await this.selectFromQuery.orderBy('id', 'asc')
303+
.limit((options.limit ?? 10) + 1)
304+
.offset(((options.page ?? 1) - 1) * (options.limit ?? 10)) // Ensure options.page is not undefined
305+
.execute()
306+
307+
let nextCursor = null
308+
if (payment_methodsWithExtra.length > (options.limit ?? 10))
309+
nextCursor = payment_methodsWithExtra.pop()?.id ?? null
310+
311+
return {
312+
data: payment_methodsWithExtra,
313+
paging: {
314+
total_records: totalRecords,
315+
page: options.page || 1,
316+
total_pages: totalPages,
317+
},
318+
next_cursor: nextCursor,
319+
}
320+
}
321+
273322
// Method to get all payment_methods
274323
static async paginate(options: QueryOptions = { limit: 10, offset: 0, page: 1 }): Promise<PaymentMethodResponse> {
275324
const totalRecordsResult = await db.selectFrom('payment_methods')

0 commit comments

Comments
 (0)