summaryrefslogtreecommitdiffstats
path: root/src/app/_layout.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/_layout.tsx')
-rw-r--r--src/app/_layout.tsx58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx
new file mode 100644
index 0000000..e2eb936
--- /dev/null
+++ b/src/app/_layout.tsx
@@ -0,0 +1,58 @@
+import { Slot, Stack } from "expo-router";
+import React, { Suspense } from 'react'
+import AppContextProvider from "../context/AppContextProvider";
+import { ActivityIndicator, Text, View } from "react-native";
+import { openDatabaseSync, SQLiteProvider } from "expo-sqlite";
+import { drizzle } from "drizzle-orm/expo-sqlite";
+import { sql } from 'drizzle-orm';
+import { migrate, useMigrations } from "drizzle-orm/expo-sqlite/migrator";
+import migrations from "../../drizzle/migrations";
+type Props = {}
+export const DATABASE_NAME = 'prueba3Drizzle';
+const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
+function LoadingScreen() {
+ return (
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
+ <ActivityIndicator size="large" color="#0000ff" />
+ <Text >Cargando la app...</Text>
+ </View>
+ );
+}
+const RootLayout = (props: Props) => {
+ return (
+ <AppContextProvider>
+ <Suspense fallback={<LoadingScreen />}>
+ <SQLiteProvider
+ databaseName={DATABASE_NAME}
+ options={{ enableChangeListener: true }}
+ useSuspense
+ onInit={async (database) => {
+ try {
+ console.log("Simulando carga lenta...");
+ await sleep(2000); // 2 segundos retraso
+ const db = drizzle(database);
+ await migrate(db, migrations);
+ console.log("Migration success");
+
+ // Activa FK aquí (después de migraciones)
+ await db.run(sql`PRAGMA foreign_keys = ON`);
+ console.log("Foreign keys enabled");
+
+ } catch (error) {
+ console.error("Migration error", error);
+ }
+ }}
+ >
+ <Stack
+ screenOptions={{ headerShown: false }}
+
+ />
+
+ </SQLiteProvider>
+ </Suspense>
+ </AppContextProvider>
+
+ )
+}
+
+export default RootLayout; \ No newline at end of file