import SQLite from "react-native-sqlite-storage" SQLite.enablePromise(true); export const MIGRATE_UP = { 1: [ `CREATE TABLE IF NOT EXIST settings ( host_language TEXT, libretranslate_base_url TEXT, ui_direction INTEGER )`, ] } export const MIGRATE_DOWN = { 1: [ `DROP TABLE IF EXISTS settings` ] } export async function getDb(migrationDirection : "up" | "down" = "up") { const db = await SQLite.openDatabase({ name: "translation_terrace", }); for (let [migration, statements] of Object.entries(MIGRATE_UP)) { for (let statement of statements) { await db.transaction(async (tx) => { await tx.executeSql(statement) }); } } return db; }