UNPKG

supastash

Version:

Offline-first sync engine for Supabase in React Native using SQLite

24 lines (23 loc) 926 B
import { getSupastashDb } from "../db/dbInitializer"; /** * Checks if the table exists in the local database * @param tableName - The name of the table to check * @returns true if the table exists, false otherwise */ export async function checkIfTableExist(tableName) { if (!tableName || typeof tableName !== "string") return false; const db = await getSupastashDb(); const exist = await db.getFirstAsync(`SELECT 1 FROM sqlite_master WHERE type='table' AND name = ? LIMIT 1;`, [tableName]); return !!exist; } /** * Throws an error if the table does not exist * @param tableName - The name of the table to check */ export async function assertTableExists(tableName) { const exists = await checkIfTableExist(tableName); if (!exists) { throw new Error(`${tableName} does not exist in the local database. Define this table using 'defineLocalSchema()' in your config file.`); } }