2025-03-09 20:16:54 -07:00

26 lines
647 B
TypeScript

import * as SQLite from "expo-sqlite";
import { MIGRATE_UP, MIGRATE_DOWN } from "./migrations";
export async function getDb() {
return await SQLite.openDatabaseAsync("translation_terrace");
}
export async function migrateDb(direction: "up" | "down" = "up") {
const db = await getDb();
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);
}
}
}
}