How do I reconnect to a database from another function?

18 views
Skip to first unread message

oscarrober...@gmail.com

unread,
Sep 1, 2017, 12:51:56 AM9/1/17
to Dexie.js
I want to reconnect to a database that I created in a previous function but I want to reopen then the database in another function. I am having trouble because I do this:

new Dexie('MyDatabase').open().then(function (db) {
console.log ("Found database: " + db.name);
console.log ("Database version: " + db.verno);
db.tables.forEach(function (table) {
console.log ("Found table: " + table.name);
console.log ("Table Schema: " +
JSON.stringify(table.schema, null, 4));
});
}).catch('NoSuchDatabaseError', function(e) {
// Database with that name did not exist
console.error ("Database not found");
}).catch(function (e) {
console.error ("Oh uh: " + e);
});


But I don't see the values that I am trying to access. Also once getting to those values how can i convert it all to a JSON string.

David Fahlander

unread,
Sep 1, 2017, 3:17:29 AM9/1/17
to Dexie.js, oscarrober...@gmail.com
This forum has moved to stackoverflow.com/questions/tagged/dexie.  I'll try answering it here anyway:

If I understand you correctly, you are not seeing things logged via console.log(). Try logging in the first line of your code, before accessing Dexie, just to narrow down the problem. console.log('something') will not show in the browser but in the console. You need to open the Javascript console from within your web browser to access it. Javascript console can be found from the browser menu. Look for "Developer tools" or "Javascript console" in the browser menu.

To convert a javascript value to JSON, use JSON.stringify().
Reply all
Reply to author
Forward
0 new messages