30 lines
707 B
TypeScript
30 lines
707 B
TypeScript
import * as SQLite from 'expo-sqlite';
|
|
|
|
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.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;
|
|
} |