2025-02-13 07:48:32 -08:00

30 lines
708 B
TypeScript

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
)`,
]
}
export const MIGRATE_DOWN = {
1: [
`DROP TABLE IF EXISTS settings`
]
}
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;
}