TypeError:undefined is not a function ..{near ...db.transacation} in react native-cli using sqlite

Viewed 879

Console Image

This is giving me errors as I have tried every method mentioned in the documents my database file is stored in the android/src/main/assets/Users_db.db still got this error and found nothing on any forum yet. Solutions mentioned on git and official documentation are followed but resulting in nothing

MyCode

import React, {Component} from 'react';
import {
  Container,
  Content,
  Header,
  Title,
  Body,
  Text,
  ListItem,
} from 'native-base';
import SQLite from 'react-native-sqlite-storage';
SQLite.DEBUG(true);

SQLite.enablePromise(true);
var database_name = 'Users_db'; // Add your Database name
var database_version = '1.0'; // Add your Database Version
var database_size = 200000; // Add your Database Size
var database_displayname = 'Users_db.db'; // Add your Database Displayname

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {usersList: []};
    // SQLite.openDatabase(
    //   {
    //     name: 'Users_db.db',
    //     createFromLocation: '~Users_db.db',
    //     location: 'Library',
    //   },
    var db = SQLite.openDatabase(
      database_name,
      database_version,
      database_displayname,
      database_size,
      this.openCB,
      this.errorCB,
    );
    // this.openCB,
    // this.errorCB,
    db.transaction(tx => {
      tx.executeSql('SELECT * FROM user_table', [], (tx, results) => {
        alert('success');
      });
    });
    // db = SQLite.openDatabase(
    //   {
    //     name: 'Users_db.db',
    //     createFromLocation: 1,
    //   },
    //   this.openCB,
    //   this.errorCB,
    //   this.successToOpenDB,
    //   this.failToOpenDB,
    // );
  }

  successToOpenDB() {
    // db.transaction((tx) => {
    //   tx.executeSql('SELECT * FROM test', [], (tx, results) => {
    //     console.log("Query completed");
    // console.log('success');
  }
  failToOpenDB(err) {
    console.log(err);
  }

  render() {
    return (
      <Container>
        <Header>
          <Body>
            <Title>The Header</Title>
          </Body>
        </Header>
        <Content>
          <ListItem>
            <Text>name hEre</Text>
            <Text>Adress will be here</Text>
          </ListItem>
        </Content>
      </Container>
    );
  }
}

2 Answers

I just removed 'SQLite.enablePromise (true);' and everything worked.

It seems to me that I followed the wrong documentation.

REMOVE THIS LINE FROM YOUR CODE

SQLite.enablePromise (true);

Related