immudb-node icon indicating copy to clipboard operation
immudb-node copied to clipboard

login and useDatabase should be globally configured

Open ethdev279 opened this issue 2 years ago • 3 comments

it looks a bit weird to call login every time we need to do operations. having client interface logged in on a global level would be more helpful so that we can export it and use it in different places.

Current:

Having no flexibility to export logged in instance

    const client = new ImmudbClient({
        host: '127.0.0.1',
        port: '3322',
        // rootPath: 'rootfile'
    });
    const main = async() => {
         // asking for login. but login should be on global level.
         const loginRes = await client.login({ user: 'immudb', password: 'immudb' })
         console.log('success: login', loginRes)

         const useDatabaseRes = await client.useDatabase({ databasename: 'immudbdev' })
         console.log('success: use database',useDatabaseRes)

        const getRes = await client.get({ key: 'key1' });
        console.log('get res: ', getRes);
}

Expected: (Like how sequelize's authentication works)

db/connector.js
const client = new ImmudbClient({
    host: '127.0.0.1',
    port: '3322',
   database: 'immudb',
    rootPath: 'rootfile'
});
client.login({ user: 'immudb', password: 'immudb' })
    .then(() => { console.log('login success') })
    .catch(err => { console.log('login failed', err) });

export default client;
src/app.js
import client from './db/connector';

const getByKey = async()=>{
   // we shouldn't need to login again
    return client.get({ key: 'key1' });
}

ethdev279 avatar Sep 13 '21 07:09 ethdev279

@ethdev279 Thanks a lot for submitting this issue to us, that's a very good idea! This will be available in the next release soon ;)

Temii avatar Sep 13 '21 08:09 Temii

Hello @Temii any update on this? I'm very curiously waiting fr this :)

ethdev279 avatar Oct 29 '21 05:10 ethdev279

Hi @ethdev279! Sorry that solving this takes more time than anticipated, we just didn't come up with a solution yet. @rafaelveggi will take care about this request from now on and will update you on the changes ;)

Temii avatar Oct 29 '21 08:10 Temii