title: SQLite database getting initialized on every app restart
body: <p>Below is my code that I am working on.</p>
  
  <p>App.js</p>
  
  <pre><code>    /**
   * Sample React Native App
   * https://github.com/facebook/react-native
   *
   * Generated with the TypeScript template
   * https://github.com/react-native-community/react-native-template-typescript
   *
   * @format
   */
  
  import * as React from 'react';
  import {
    SafeAreaView,
    StyleSheet,
    ScrollView,
    View,
    Text,
    StatusBar,
  } from 'react-native';
  
  import {
    Header,
    LearnMoreLinks,
    Colors,
    DebugInstructions,
    ReloadInstructions,
  } from 'react-native/Libraries/NewAppScreen';
  import SQLite from "react-native-sqlite-storage";
  
  const database_name = "Test.db";
  const database_version = "1.0";
  const database_displayname = "SQLite Test Database";
  const database_size = 200000;
  SQLite.enablePromise(true);
  
  let db;
  type InitState={
    firstTimeUsage:boolean,
    errorOccured:boolean,
    errorMessage:string
  }
  
  export default class App extends React.Component&lt;{},InitState&gt;{
    constructor(props:any){
      super(props);
      this.state={
        firstTimeUsage:null,
        errorOccured:false,
        errorMessage:null
      }
    }
  
    componentDidMount(){
      console.log("Component did mount called");
      SQLite.openDatabase(database_name, database_version, database_displayname, database_size).then((DB)=&gt;{
        console.log("database opened");
        db = DB;
        if(this.checkFirstTimeUsage(db)){
          this.createTable(db);
        }else{
          this.setState({firstTimeUsage:false});
        }
      }).catch((error)=&gt;{
        console.log("error occured opening database");
        this.setState({errorOccured:true,errorMessage:"Error validating app installation"});
      });
    }
  
    createTable = (database:any) =&gt; {
      console.log("Creating table");
      database.transaction((tx:SQLite.transaction)=&gt;{
        tx.executeSql("CREATE TABLE IF NOT EXISTS PROFILE_MASTER (PLAYER_TAG VARCHAR(10) PRIMARY KEY NOT NULL,DEFAULT_IND VARCHAR(1) NOT NULL);")
        .then(([tx,results]) =&gt; {
          console.log("Table created");
          this.setState({firstTimeUsage:true});
        }).catch((_error: any)=&gt;{
          console.log("error occured creating table");
          this.setState({errorOccured:true,errorMessage:"Error initializing app"})
        });
        tx.executeSql("INSERT into PROFILE_MASTER (PLAYER_TAG,DEFAULT_IND) values ('ASDC','Y')")
        .then(([results])=&gt;{
          console.log("added data to table");
          console.log(results);
        }).catch((error: any) =&gt; {
          console.log("error adding data to table");
          console.log(error)
        })
      })
    }
  
  
    checkFirstTimeUsage = async (database:SQLite.SQLiteDatabase) =&gt; {
      return await database.transaction((tx)=&gt;{
        tx.executeSql("SELECT name from sqlite_master where type='TABLE' and name = 'PROFILE_MASTER'",null).
        then(([tx,results])=&gt;{
          if(results.rows.length===0){
            return true;
          }else{
            return false;
          }
        })
      }).catch((error)=&gt;{
        console.log(error);
        return false;
      })
    }
    render(){
      console.log("first time usage is "+this.state.firstTimeUsage);
      return (
        &lt;&gt;
          &lt;StatusBar barStyle="dark-content" /&gt;
          &lt;SafeAreaView&gt;
            &lt;ScrollView
              contentInsetAdjustmentBehavior="automatic"
              style={styles.scrollView}&gt;
              &lt;Header /&gt;
              &lt;View style={styles.body}&gt;
                &lt;View style={styles.sectionContainer}&gt;
                  &lt;Text style={styles.sectionTitle}&gt;Step One{this.state.firstTimeUsage}&lt;/Text&gt;
                  &lt;Text style={styles.sectionDescription}&gt;
                    Edit &lt;Text style={styles.highlight}&gt;App.tsx&lt;/Text&gt; to change this
                    screen and then come back to see your edits.
                  &lt;/Text&gt;
                &lt;/View&gt;
                &lt;View style={styles.sectionContainer}&gt;
                  &lt;Text style={styles.sectionTitle}&gt;See Your Changes&lt;/Text&gt;
                  &lt;Text style={styles.sectionDescription}&gt;
                    &lt;ReloadInstructions /&gt;
                  &lt;/Text&gt;
                &lt;/View&gt;
                &lt;View style={styles.sectionContainer}&gt;
                  &lt;Text style={styles.sectionTitle}&gt;Debug&lt;/Text&gt;
                  &lt;Text style={styles.sectionDescription}&gt;
                    &lt;DebugInstructions /&gt;
                  &lt;/Text&gt;
                &lt;/View&gt;
                &lt;View style={styles.sectionContainer}&gt;
                  &lt;Text style={styles.sectionTitle}&gt;Learn More&lt;/Text&gt;
                  &lt;Text style={styles.sectionDescription}&gt;
                    Read the docs to discover what to do next:
                  &lt;/Text&gt;
                &lt;/View&gt;
                &lt;LearnMoreLinks /&gt;
              &lt;/View&gt;
            &lt;/ScrollView&gt;
          &lt;/SafeAreaView&gt;
        &lt;/&gt;
      );
    }
  }
  
  const styles = StyleSheet.create({
    scrollView: {
      backgroundColor: Colors.lighter,
    },
    engine: {
      position: 'absolute',
      right: 0,
    },
    body: {
      backgroundColor: Colors.white,
    },
    sectionContainer: {
      marginTop: 32,
      paddingHorizontal: 24,
    },
    sectionTitle: {
      fontSize: 24,
      fontWeight: '600',
      color: Colors.black,
    },
    sectionDescription: {
      marginTop: 8,
      fontSize: 18,
      fontWeight: '400',
      color: Colors.dark,
    },
    highlight: {
      fontWeight: '700',
    },
    footer: {
      color: Colors.dark,
      fontSize: 12,
      fontWeight: '600',
      padding: 4,
      paddingRight: 12,
      textAlign: 'right',
    },
  });
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "StatsRoyaleMulti",
    "version": "0.0.1",
    "private": true,
    "scripts": {
      "android": "react-native run-android",
      "ios": "react-native run-ios",
      "start": "react-native start",
      "test": "jest"
    },
    "dependencies": {
      "react": "16.9.0",
      "react-native": "0.61.1",
      "react-native-sqlite-storage": "^4.1.0"
    },
    "devDependencies": {
      "@babel/core": "^7.6.2",
      "@babel/runtime": "^7.6.2",
      "@react-native-community/eslint-config": "^0.0.5",
      "@types/jest": "^24.0.18",
      "@types/react": "^16.9.4",
      "@types/react-native": "^0.60.17",
      "@types/react-test-renderer": "16.9.0",
      "babel-jest": "^24.9.0",
      "jest": "^24.9.0",
      "metro-react-native-babel-preset": "^0.56.0",
      "react-test-renderer": "16.9.0",
      "typescript": "^3.6.3"
    },
    "jest": {
      "preset": "react-native",
      "moduleFileExtensions": [
        "ts",
        "tsx",
        "js",
        "jsx",
        "json",
        "node"
      ]
    }
  }
  </code></pre>
  
  <p>Console log:</p>
  
  <pre><code>Running "StatsRoyaleMulti" with {"rootTag":1}
   LOG  first time usage is null
   LOG  Component did mount called
   LOG  database opened
   LOG  Creating table
   LOG  Table created
   LOG  first time usage is true
   LOG  added data to table
   LOG  {"db": {"dbname": "Test.db", "openError": [Function error], "openSuccess": [Function success], "openargs": {"dblocation": "nosync", "name": "Test.db"}}, "error": [Function error], "executes": [], "finalized": true, "fn": [Function anonymous], "readOnly": false, "success": [Function success], "txlock": true}
  
  
   LOG  Running "StatsRoyaleMulti" with {"rootTag":11}
   LOG  first time usage is null
   LOG  Component did mount called
   LOG  database opened
   LOG  Creating table
   LOG  Table created
   LOG  first time usage is true
   WARN  Possible Unhandled Promise Rejection (id: 0):
  Object {
    "code": 0,
    "message": "UNIQUE constraint failed: PROFILE_MASTER.PLAYER_TAG (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)",
  }
  </code></pre>
  
  <p><strong>What is happening :</strong> When the app is launched I am checking if a table exists. If it does not exists then I am creating the table. I close the app and open it again and I see that the table is getting created again.</p>
  
  <p><strong>What I am expecting to happen:</strong> The first launch of the app should create the table and subsequent launches should find that the table exists and should not create it again.</p>
  
  <p>Can you guys tell me what I am doing wrong here.</p>