import * as SQLite from 'expo-sqlite'; export const MIGRATE_UP = { 1: [ `CREATE TABLE IF NOT EXISTS settings ( host_language TEXT, libretranslate_base_url TEXT, ui_direction INTEGER )`, ], 2: [ `CREATE TABLE IF NOT EXISTS whisper_models ( model TEXT PRIMARY KEY, bytes_done INTEGER, bytes_total INTEGER, )`, ] } export const MIGRATE_DOWN = { 1: [ `DROP TABLE IF EXISTS settings` ], 2: [ `DROP TABLE IF EXISTS whisper_models` ] } export async function getDb(migrationDirection : "up" | "down" = "up") { const db = await SQLite.openDatabaseAsync('translation_terrace'); for (let [migration, statements] of Object.entries(MIGRATE_UP)) { for (let statement of statements) { console.log(statement) await db.runAsync(statement); } } return db; }