Skip to content

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

Closed
@Adokiye

Description

@Adokiye

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

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions