Closed osc2nuke closed 8 years ago
Hey, I'm not sure what's the question is, but if you just copy/run example in console, it will work and give you a good starting point.
cant use db.store('theName') if not rebuild schema
If answer on your title, yes, you can't, because IndexedDB uses static schemas.
Mmm to bad, then i cannot use the wrapper ( i think not can call it a wrapper anymore, if need to rebuild each time the schema on a page reload), but hey!!!!! Still it is good work.
Thanks, FYI: IndexedDB does not rebuild schema on page reload, you just pass it, and if current version is 3, upgrade
event is skipped. Treo also uses schema
object to define internal structure of available stores/indexes.
i think i not understand the whole concept, perhaps you can enlightening me . This is what i trying... Check the console.log WORKS/FAILS (tnx in advanced)
//Works
function doCreate(){
// define db schema
var schema = treo.schema()
.version(1)
.addStore('books', { key: 'isbn' })
.addIndex('byTitle', 'title', { unique: true })
.addIndex('byAuthor', 'author')
.version(2)
.getStore('books')
.addIndex('byYear', 'year')
.version(3)
.addStore('magazines')
.addIndex('byPublisher', 'publisher')
.addIndex('byFrequency', 'frequency');
// open db
var db = window.treo('library', schema);
db.version; // 3
// put some data in one transaction
var books = db.store('books');
books.batch([
{ isbn: 123456, title: 'Quarry Memories', author: 'Fred', year: 2012 },
{ isbn: 234567, title: 'Water Buffaloes', author: 'Fred', year: 2012 },
{ isbn: 345678, title: 'Bedrock Nights', author: 'Barney', year: 2013 },
], function(err) {
// Before this point, all actions were synchronous, and you don't need to wait
// for db.open, initialize onupgradeneeded event, create readwrite transaction,
// and handle all possible errors, blocks, aborts.
// If any error happen on one of this steps, you get it as `err`.
});
// get a single book by title using an index
books.index('byTitle').get('Bedrock Nights', function(err, book) {
console.log(book);//WORKS!!!!!
});
// get all books filtered by author
books.index('byAuthor').get('Fred', function(err, all) {}); // all.length == 2
}
//Fails
function getItem(){
// define db schema
var schema = treo.schema();
// open db
var db = window.treo('library', schema);
db.version; // 3
// put some data in one transaction
var books = db.store('books');
// get a single book by title using an index
books.index('byTitle').get('Bedrock Nights', function(err, book) {
console.log(book);//FAILS!!!!!
});
// get all books filtered by author
books.index('byAuthor').get('Fred', function(err, all) {}); // all.length == 2
}
Keep in mind i fire first the WORKING after i directly fire the FAILING , regardless if i reload the page or not.
Just always pass the whole schema in treo constructor.
var schema = treo.schema(); // bug, it's an empty schema
Im want to using the standalone version of treo for my project. Inside it i made a function
function myFunction(){}
I fire it and all works out of the box as the "library" example.The database is builded correctly and i not require anymore the creations of the tables as:
So i now just use :
Right? i also take out the batch process:
books.batch([............ETC....});
Right? Now i expect to use the :
Cause the whole db and schema is handled via treo.js ..... right? But i get:
I have tried everything i know.... but it keeps failing.
Hope to find quickly a solution!!! Greetings Henry!!!