Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

Basic web example doesn't work in Safari #237

Closed pkrefta closed 5 years ago

pkrefta commented 5 years ago

Hi guys,

I've started playing with Watermelon and created basic example

import { Database, Model } from '@nozbe/watermelondb'
import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs'
import { field } from '@nozbe/watermelondb/decorators'
import { appSchema, tableSchema } from '@nozbe/watermelondb'

class Note extends Model {
  static table = 'notes'

  @field('title') title
  @field('body') body
}

const schema = appSchema({
  version: 1,
  tables: [
    tableSchema({
      name: 'notes',
      columns: [
        { name: 'title', type: 'string' },
        { name: 'body', type: 'string' },
      ]
    }),
  ]
})

const adapter = new LokiJSAdapter({
  schema,
})

let database = new Database({
  adapter,
  modelClasses: [
    Note
  ],
  // actionsEnabled: true,
})

const notes = database.collections.get('notes')

notes.query().fetchCount().then((count) => {
  console.log('count ' + count)
})

console.log outputs number in Chrome but Safari reports an error Diagnostic error: TypeError: null is not an object (evaluating 'loki.getCollection(query.table).chain')

radex commented 5 years ago

can you dig deeper into the errors to see what's up? looks like query.table is null… but why?

perhaps misconfigured Babel, and static table = 'notes' doesn't work correctly?

pkrefta commented 5 years ago

I've pushed my code here https://github.com/pkrefta/watermelon-fun I'm using skeleton application from CRA and I think my configs are fine since it's working OK in Chrome :)

pkrefta commented 5 years ago

I got it going - my bad.

radex commented 5 years ago

nice @pkrefta!

kldkv commented 5 years ago

I solved the problem by deleting the indexeddb in browser