From 7809ccbba56be8c5377f94cf2d287a0e1521fdc1 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Wed, 25 Mar 2026 15:32:20 +0000 Subject: Initial commit: App Oficina base project --- src/app/GuardarProducto.tsx | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/app/GuardarProducto.tsx (limited to 'src/app/GuardarProducto.tsx') diff --git a/src/app/GuardarProducto.tsx b/src/app/GuardarProducto.tsx new file mode 100644 index 0000000..abdd8c1 --- /dev/null +++ b/src/app/GuardarProducto.tsx @@ -0,0 +1,61 @@ +import { StyleSheet, Text, View, Button, Alert} from 'react-native' +import React from 'react' +import { useSQLiteContext } from 'expo-sqlite'; +import { drizzle, useLiveQuery } from 'drizzle-orm/expo-sqlite'; +//import { personas, categorias, productos } from '../db/schema'; +import { SafeAreaView } from 'react-native-safe-area-context'; + + +const GuardarProducto = () => { + const db = useSQLiteContext(); + + /* + const drizzleDb = drizzle(db, { schema: { personas } }); + const { data: listaCategorias } = useLiveQuery(drizzleDb.select().from(categorias)); + const { data: listaProductos } = useLiveQuery(drizzleDb.select().from(productos)); + + async function almacenarCategoria(){ + let edadAleatoria = Math.trunc(Math.random()*100); + let nombreAleatorio = "categoria_"+Math.trunc(Math.random()*10000); + await drizzleDb.insert(categorias).values({ nombre: nombreAleatorio }); + } + + async function almacenarProducto(){ + let edadAleatoria = Math.trunc(Math.random()*100); + let nombreAleatorio = "producto_"+Math.trunc(Math.random()*10000); + let precioAleatorio = (Math.trunc(Math.random()*10000) ) / 100 + if( listaCategorias.length <= 0 ){ + Alert.alert("No hay categorías aún. No se guarda producto"); + return; + } + let posCategoria = Math.trunc(Math.random()*listaCategorias.length); + let idCategoria = listaCategorias[posCategoria].id; + + await drizzleDb.insert(productos).values({ nombre: nombreAleatorio, precio: precioAleatorio, categoriaId: idCategoria }); + } + */ + return ( + + + + + {/* + Guardar Categoría +