mafintosh / hyperdb

Distributed scalable database
MIT License
752 stars 75 forks source link

Cannot find a way to catch Error: Another hypercore is stored here error #164

Open aral opened 5 years ago

aral commented 5 years ago

When creating a new database, if you erroneously try to create a new database over an existing one, you get Error: Another hypercore is stored here. However, I can find no way of catching this error so that I can handle it gracefully when using hyperdb.

m-onz commented 5 years ago

Just fs.stat the DB folder before attempting to create the new db.

On Sat, Feb 16, 2019, 10:23 Aral Balkan <notifications@github.com wrote:

When creating a new database, if you erroneously try to create a new database over an existing one, you get the Error: Another hypercore is stored here. However, I can find no way of catching this error so that I can handle it gracefully.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mafintosh/hyperdb/issues/164, or mute the thread https://github.com/notifications/unsubscribe-auth/ANY6RmmcFPhd3IL-iA-o3NP67V4dcGBcks5vN9wngaJpZM4a-6hr .

aral commented 5 years ago

@m-onz Sorry, I should’ve been more precise: this is with random-access-idb in the browser and, afaics, there doesn’t seem to be a reliable way to see if an IndexDB database exists or not (!!!)

m-onz commented 5 years ago

I've used hyperdb in the browser... Using substacks lib. The DB name creates a key from your DB name.. Surely you can check that exists. I think supplying the DB key as the second argument of the constructor each time might work too.

On Sat, Feb 16, 2019, 17:01 Aral Balkan <notifications@github.com wrote:

@m-onz https://github.com/m-onz Sorry, I should’ve been more precise: this is with random-access-idb in the browser and, afaics, there doesn’t seem to be a reliable way to see if an IndexDB database exists or not (!!!)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mafintosh/hyperdb/issues/164#issuecomment-464362876, or mute the thread https://github.com/notifications/unsubscribe-auth/ANY6Rtr6KH6-dEgWsqpTRC_X4Cr3Jpb7ks5vODlPgaJpZM4a-6hr .

aral commented 5 years ago

Regarding my previous point: https://stackoverflow.com/a/23767548

joehand commented 5 years ago

I was running into this too and decided to use the discovery key so you can store multiple dats:

var crypto = require('hypercore-crypto')
var db = require('random-access-idb')

var key = 'dat://somedatkey'

var discoveryKey = crypto.discoveryKey(key)
var archive = hyperdrive(db(discoveryKey.toString('hex')), key)
m-onz commented 5 years ago

Also, you could store your DB name in local storage or as a cookie.

Bit crude but its a work around.