codenotary / immudb-node

Node.js SDK for immudb
Apache License 2.0
63 stars 3 forks source link

login and useDatabase should be globally configured #14

Closed ethdev279 closed 1 year ago

ethdev279 commented 3 years ago

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' });
}
Temii commented 3 years ago

@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 ;)

ethdev279 commented 3 years ago

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

Temii commented 3 years ago

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 ;)

tomekkolo commented 1 year ago

closing as immudb-node was updated to v2