Skip to content

Instantly share code, notes, and snippets.

@kanzitelli
Last active December 7, 2021 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanzitelli/e058b7eaeaf7d27ff6314c0faeb906b7 to your computer and use it in GitHub Desktop.
Save kanzitelli/e058b7eaeaf7d27ff6314c0faeb906b7 to your computer and use it in GitHub Desktop.
Get more than 1000 records from Supabase database in one function
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