Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError:undefined is not a function(evaluating'_realm2.default.open(databaseOptions)') #20306

Closed
Adokiye opened this issue Jul 20, 2018 · 1 comment
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@Adokiye
Copy link

Adokiye commented Jul 20, 2018

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>
    );
}
}
@Adokiye Adokiye changed the title Realm not working on React native android TypeError:undefined is not a function(evaluating'_realm2.default.open(databaseOptions)') Jul 20, 2018
@react-native-bot
Copy link
Collaborator

We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

Please make use of the bug report template to let us know about a reproducible bug or regression in the core React Native library.

If you'd like to start a discussion, check out https://discuss.reactjs.org or follow the discussion template.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. 📋No Template labels Jul 20, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants