import * as SQLite from "expo-sqlite"; import { MIGRATE_UP, MIGRATE_DOWN } from "./migrations"; export type db_mode = "development" | "staging" | "production"; export async function getDb(mode : db_mode = "production") { return await SQLite.openDatabaseAsync(`translation_terrace_${mode}`); } export async function migrateDb(mode : db_mode = "production", direction: "up" | "down" = "up") { const db = await getDb(mode); const m = direction === "up" ? MIGRATE_UP : MIGRATE_DOWN; for (let [migration, statements] of Object.entries(m)) { for (let statement of statements) { console.log(statement); try { const result = await db.runAsync(statement); console.log(result); } catch (err) { console.error(err); } } } }