-
-
Notifications
You must be signed in to change notification settings - Fork 641
Table.mapToClass()
David Fahlander edited this page Mar 28, 2014
·
18 revisions
Map the table to an existing javascript class
table.mapToClass(constructor, structure)
constructor: Function | Javascript constructor function | |
structure: Object | Definition of the properties available on instances of the class | optional |
Same constructor function as given as argument.
Makes any object extracted from this table be instanceof your given constructor function. You could extend the prototype of the given constructor with methods that will be available on all objects returned by the database.
If calling this method before db.open() call, intelligent javascript editors like Visual Studio 2012+ and IntelliJ will be able to do autocomplete for all objects returned by the database, based on the prototype of the constructor and on given structure.
function Car() {}
function Friend() {
}
Friend.prototype.log = function () {
console.log(JSON.stringify(this));
}
db.friends.mapToClass (Friend, {
name: String,
shoeSize: Number,
cars: [Car],
address: {
street: String,
city: String,
country: String
}
});
Dexie.js - minimalistic and bullet proof indexedDB library