Last active
December 7, 2021 20:51
-
-
Save kanzitelli/e058b7eaeaf7d27ff6314c0faeb906b7 to your computer and use it in GitHub Desktop.
Get more than 1000 records from Supabase database in one function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const N = 500; | |
const getAll = async (prefix: string): Promise<T[]> => { | |
const allData: T[] = []; | |
let dataLen = 0; | |
let i = 1; | |
do { | |
const { data, error } = await supabase | |
.from('table') | |
.select('*') | |
.range((i - 1) * N, i * N - 1); | |
checkDBError(error); | |
const dataToAdd = data ?? []; | |
dataLen = dataToAdd.length; | |
allData.push(...dataToAdd); | |
i += 1; | |
} while (dataLen !== 0); | |
return allData; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment