healthhackersER / CAMA-CORE-Example

4 stars 1 forks source link

[DB] Native Database Implementation - SQLite #8

Open IvoLeist opened 4 years ago

IvoLeist commented 4 years ago

Target

Native database to store application data on the device only (e.g. App Sandbox)

Goal

Possible Solution

GundlackFelixDEV commented 4 years ago

First Problem: [Example] of SQLite Database in React Native is an example for IOs

See [HowTo] Using CocoaPods on Windows

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. With over 60 thousand libraries, it is the most popular repository of its kind, impacting over 3 million apps (quoting the official site). Traditionally, the CocoaPods only targeted macOS, which made sense as it was meant to work with Xcode and the related toolchain. However, the success of cross-platform development frameworks such as Flutter or React Native gave rise to demand for CocoaPods to work on non-macOS platforms such as Windows (for example, some folks have reported issues #8055 and #8077).

BUT - There might be a solution

Starting with CocoaPods 1.7 (in Beta as of time of writing), it is now possible to get some basic operations, such as pod install and pod update to run on Windows. This guide walks through the necessary steps to get this to work.

--> What a pain in the ass and a clutter of environments to setup 🤢🤮😰

Next: I will try to follow the instructions from the README.md of the library implementation https://github.com/andpor/react-native-sqlite-storage

GundlackFelixDEV commented 4 years ago

Bin gerade am überlegen ob wir nicht auf WebSQL gehen sollten...

Hier eine übersicht übre mögliche speichermöglichkeiten welche von Browsern von HausAuf unterstützt werden:

<!DOCTYPE HTML> 

<html>  
   <head> 

      <script type = "text/javascript"> 
         var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024); 
         var msg; 

         db.transaction(function (tx) { 
            tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)'); 
            tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")'); 
            tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")'); 
            msg = '<p>Log message created and row inserted.</p>'; 
            document.querySelector('#status').innerHTML =  msg; 
         })

         db.transaction(function (tx) { 
            tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) { 
               var len = results.rows.length, i; 
               msg = "<p>Found rows: " + len + "</p>"; 
               document.querySelector('#status').innerHTML +=  msg; 

               for (i = 0; i < len; i++) { 
                  msg = "<p><b>" + results.rows.item(i).log + "</b></p>"; 
                  document.querySelector('#status').innerHTML +=  msg; 
               } 
            }, null); 
         }); 
      </script> 
   </head> 

   <body> 
      <div id = "status" name = "status">Status Message</div> 
   </body> 
</html>
IvoLeist commented 4 years ago

Habe jetzt auch Mal ein bisschen gegoogelt WebSQL scheint deprecated zu sein deswegen bin ich weiterhin für sqlite

https://www.joshmorony.com/a-summary-of-local-storage-options-for-phonegap-applications/

kompromiss-chris commented 4 years ago

Hier mal ein Beispiel mit expo-sqlite:


import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import { FileSystem } from 'expo';
import * as SQLite from 'expo-sqlite';

const db = SQLite.openDatabase('cancer-data.sqlite');
db.exec([{ sql: 'CREATE TABLE IF NOT EXISTS Test(id int,test text)', args: [] }], true, () => {});
const insertSql = async () => {
  db.exec([{ sql: 'INSERT 1,"Hello" INTO Test', args: [] }], false, () => {});
};

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={{ color: 'green' }}>Open up App.tsx to start working on your app!</Text>
      <Button title="INSERT" onPress={insertSql} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#000',
    alignItems: 'center',
    justifyContent: 'center'
  }
});
`
GundlackFelixDEV commented 4 years ago

Implementation for local data base manager: