const recursiveFunc = async (params: {
db: PlanetScaleDatabase<Schema>
// unknown for demo purpose
data?: ReadonlyArray<unknown>
offSet?: number
pageSize?: number
}) => {
const { db, data = [], offSet = 0, pageSize = 100000 } = params
// the query is where we get the data
const dataQuery = await db
.select()
.from(mySqlTable)
.offset(offSet)
.limit(pageSize)
// we save the data by passing the data back into itself
const dataSave = pipe(data, ReadonlyArray.appendAll(dataQuery))
return pipe(
ReadonlyArray.length(dataQuery) < pageSize,
Boolean.match({
onFalse: () =>
// if we dont have all the records run it again with new offset
recursion({
db,
data: dataSave,
offSet: ReadonlyArray.length(dataSave),
}),
// returns when we have all the records from the db
onTrue: () => dataSave,
}),
)
}
const recursiveFunc = async (params: {
db: PlanetScaleDatabase<Schema>
// unknown for demo purpose
data?: ReadonlyArray<unknown>
offSet?: number
pageSize?: number
}) => {
const { db, data = [], offSet = 0, pageSize = 100000 } = params
// the query is where we get the data
const dataQuery = await db
.select()
.from(mySqlTable)
.offset(offSet)
.limit(pageSize)
// we save the data by passing the data back into itself
const dataSave = pipe(data, ReadonlyArray.appendAll(dataQuery))
return pipe(
ReadonlyArray.length(dataQuery) < pageSize,
Boolean.match({
onFalse: () =>
// if we dont have all the records run it again with new offset
recursion({
db,
data: dataSave,
offSet: ReadonlyArray.length(dataSave),
}),
// returns when we have all the records from the db
onTrue: () => dataSave,
}),
)
}