- 
                Notifications
    
You must be signed in to change notification settings  - Fork 24.9k
 
Closed
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
I have a js file where I declared my schemas, the database options and functions that insert data, query data from the schema.
I am running the app on an android emulator, anytime I try to insert data it always comes back with this error TypeError:undefined is not a function(evaluating'_realm2.default.open(databaseOptions)') , can anyone please help, I've been stuck on it for days :(
ALLSCHEMAS.JS
import Realm from 'realm';
export const PERSON_SCHEMA = "Person";
export const PersonSchema = {
name: PERSON_SCHEMA,
primaryKey: 'id',
properties: {
    id: 'int',
    name: {type: 'string', indexed: true}
}
};
const databaseOptions = {
path: 'person.realm',
schema: [PersonSchema],
schemaVersion: 0
};
export const insertNewPerson = newPerson => new Promise((resolve, reject)=>{
Realm.open(databaseOptions).then(realm => {
    realm.write(() => {
        realm.create(PERSON_SCHEMA, newPerson);
        resolve(newPerson);
    });
}).catch((error) => reject(error));
});
export const queryAll = () => new Promise((resolve, reject) => {
Realm.open(databaseOptions).then(realm => {
    let allPersons = realm.objects(PERSON_SCHEMA);
    resolve(allPersons);
}).catch((error) => {
    reject(error);
});
});
export default new Realm(databaseOptions);
APP.JS
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {insertNewPerson, queryAll} from "./databases/allSchemas";
 export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {timePassed: false, value: '', realm: "books"};
  }
  render() {
    const newPerson = {
        id: Math.floor(Date.now() / 1000),
        name: this.state.realm
    };
    insertNewPerson(newPerson).then().catch((error) => {
        alert(error);
    });
    queryAll().then((value) => {
        this.setState({value});
    }).catch((error) => {
    })
    return (
        <View>
            <Text>
                {this.state.value}
            </Text>
        </View>
    );
}
}
Metadata
Metadata
Assignees
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.