Open arnemorken opened 7 years ago
I agree that it is not really awesome - but the reason is that you are trying to do a sync call to each statement in the second one. At the moment this assumes each statement is sync, but attatching the indexxed DB is async, so the geo table is not created yet.
I suggest using the lazy promise notation as follows:
alasql(['CREATE INDEXEDDB DATABASE IF NOT EXISTS geo',
'ATTACH INDEXEDDB DATABASE geo',
'USE geo'].then(function(){
// now geo is ready to be used
}).catch(console.log)
´´´
Thank you for your reply. I can see that asynchronous execution might be the problem in my original code. However, this code, which I believe should be synchronous, also fails and prints "Error: Database 'geo2' does not exist" to the console:
alasql(['CREATE INDEXEDDB DATABASE IF NOT EXISTS geo2',
'ATTACH INDEXEDDB DATABASE geo2',
'USE geo2'])
.then( function() { console.log("ok"); })
.catch( function(err) { console.log(err); })
hmmmmm...
Can you do me a favour and test if it works if you do not have the IF NOT EXISTS geo2
part?
If I remove "IF NOT EXISTS" I get the same error message "Error: Database 'geo2' does not exist", but also:
Error: IndexedDB: Cannot create new database "geo2" because it already exists alasql.js:16314:11
So it does not exist and it already exists... seems like alasql is having an existential crisis! :)
Using alasql v0.3.9. This works (in browser):
This gives "Error: Database 'geo' does not exist" in the console: