0

I have this problem on jayData: I try to create this simple database:

var x=$data.Entity.extend("Person",
{
  ID: {type: "int", key:true, required: true},
  Name: {type: "string", required: true}
});

$data.EntityContext.extend("PersonDatabase",
{
  People: {type: $data.EntitySet, elementType: Person}
});

var DB1=new PersonDatabase({
  provider: 'webSql',
  databaseName:'DB1',
});

Which works perfectly. But when I simply switch the database type to indexxedDb, it doesn't do anything.

var x=$data.Entity.extend("Person",
{
  ID: {type: "int", key:true, required: true},
  Name: {type: "string", required: true}
});

$data.EntityContext.extend("PersonDatabase",
{
  People: {type: $data.EntitySet, elementType: Person}
});

var DB1=new PersonDatabase({
  provider: 'indexedDb',
  databaseName:'DB1',
  version: 1
});

Any ideas?

1 Answers1

1

There is only one thing to fix in this code: the ID field should be computed instead of required. Once you change it, JayData will autogenerate the ID for you.

var x=$data.Entity.extend("Person",
{
    Id: {type: "int", key:true, computed: true},
  Name: {type: "string", required: true}
});

$data.EntityContext.extend("PersonDatabase",
{
  People: {type: $data.EntitySet, elementType: Person}
});

var DB1=new PersonDatabase({ provider: 'indexedDb', databaseName:'DB1', version: 1 });

DB1.onReady(function() {
    DB1.People.add({ Name: 'Jay Data'});
    DB1.saveChanges();
});

Does this fix your issue?

Robesz
  • 1,646
  • 11
  • 13
  • Sadly, no. I tried exactly the same code but the indexeddb database has not created. When I look what to the variable DB1, i see: PersonDatabase {lazyLoad: false, trackChanges: false, _entitySetReferences: Object, _storageModel: Array[1], _isOK: "Provider fallback failed!"…}. Do you have any ideas? – AutomaticHourglass May 14 '13 at 05:51
  • Try to include the /jaydataproviders/IndexedDbProvider.js after jaydata.js. – Robesz May 14 '13 at 06:11
  • One question: In what browser does this happen? – Robesz May 14 '13 at 06:13
  • I figured it out, i included websql and indexeddb database on the same page, deleted websql one, database worked. BUT, the database created does not showing on the chrome->inspect element/resources tab, while i can query the database and it gives correct results. @Robesz, i tried the first one, nothing changes. Second, browser is Google Chrome v26 – AutomaticHourglass May 14 '13 at 08:00
  • 1
    Sometimes I forget that I had to click the "Refresh IndexedDb" to get the records in the Chrome Resources window. This is a standard Chrome behavior, and frustrating after using inspecting Web SQL tables in a comfortable way. Do you get the records after right-click -> refresh Indexeddb? – Robesz May 14 '13 at 08:27