dflourusso / expo-sqlite-orm

Expo SQLite ORM
132 stars 34 forks source link

I used the Animal Example used in the Document #6

Closed burhanahmed92 closed 5 years ago

burhanahmed92 commented 5 years ago

I am Using the Latest Expo Version 32.0.0. Added this libray with given yarn code.

Now when i run the Animal Example it shows this warning in console

Possible Unhandled Promise Rejection (id: 0): Object :{}

Kindly tell what am i missing

I tried several time & rebuilt the project couple of time. Still it shows the error

My Code


import { SQLite } from 'expo'
import { BaseModel, types } from 'expo-sqlite-orm'

export default class Animal extends BaseModel {
  constructor(obj) {
    super(obj)
  }

  static get database() {
    return Promise.resolve(SQLite.openDatabase('database.db'))
  }

  static get tableName() {
    return 'animals'
  }

  static get columnMapping() {
    return {
      id: { type: types.INTEGER, primary_key: true }, // For while only supports id as primary key
      name: { type: types.TEXT, not_null: true },
      color: { type: types.TEXT },
      age: { type: types.NUMERIC },
      another_uid: { type: types.INTEGER, unique: true },
      timestamp: { type: types.INTEGER, default: () => Date.now() }
    }
  }
}

My App.JS


import React from 'react';
import { View } from 'react-native';
import Animal from './Animal';

export default class App extends React.Component {
    async componentDidMount() {
        await Animal.createTable();
        await Animal.create({
            id: 1,
            name: '', // <- empty string
            color: 'Brown',
            age: 2
        });
        const createdAnimal = await Animal.find(1);
        console.log(createdAnimal);
    }

    render() {
        return ( <View /> );
    }
}
dflourusso commented 5 years ago

I will check it

dflourusso commented 5 years ago

Sorry for the wrong docs, i already fixed it. The getter database must return an async function, not promise.

static get database() {
  return async () => SQLite.openDatabase('database.db')
}

Thanks for the contribution.

SomnathKadam commented 4 years ago

for expo cli version 3.11.3 use below line for import

import * as SQLite from 'expo-sqlite';