dflourusso / expo-sqlite-orm

Expo SQLite ORM
132 stars 34 forks source link

EventDatabase.create(props) #23

Closed aekryz1993 closed 4 years ago

aekryz1993 commented 4 years ago

when create a record it created but it give this error:

undefined is not an object (evaluating 'obj.hasOwnProperty')**

  • node_modules/expo-sqlite-orm/src/DataTypes.js:31:9 in toModelValue
  • [native code]:null in reduce
  • node_modules/expo-sqlite-orm/src/DataTypes.js:30:42 in toModelValue
  • node_modules/expo-sqlite-orm/src/Repository.js:20:42 in insert
  • node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  • node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
  • [native code]:null in callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
  • [native code]:null in flushedQueue
  • [native code]:null in invokeCallbackAndReturnFlushedQueue

My code:

class User extends BaseModel {
  constructor(obj) {
    super(obj)
  }

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

  static get tableName() {
    return 'users'
  }

  static get columnMapping() {
    return {
      id: { type: types.TEXT, primary_key: true }, 
      username: { type: types.TEXT, not_null: true, unique: true },
      password: { type: types.TEXT, not_null: true},
      isAdmin: { type: types.NUMERIC, default: 0 },
      timestamp: { type: types.INTEGER, default: () => Date.now() }
    }
  }
}
export const addUser = (data) => {

  return new Promise(async (resolve, reject) => {
    try {
      const user = await User.create({
        id: data.id,
        username: data.username,
        password: data.password,
        isAdmin: data.isAdmin,
      })

      resolve({ message: 'Successfully Added' })
    } catch (error) {
      console.log(error)
      reject({ error: 'failled...' })
    }
  })
}
aekryz1993 commented 4 years ago

I fixed the issue with remove the assigned id record and turn dataType id to INTEGER