Giter Site home page Giter Site logo

Comments (9)

6uliver avatar 6uliver commented on May 25, 2024 1

Thank you very much!
I reviewed the commit and LGTM. In the next days I will try it.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hi,
What is the use case of having several instances? Is it just to have different namespace? In that case all the methods accept a namespace argument that should allow switching namespace anytime.

const namespace = require('./config').namespace1; // for example

Model.get(123, null, namespace).then( ... );

Would that not work for you?

from gstore-node.

jainanshul avatar jainanshul commented on May 25, 2024

That should work, however 1) It seems unnecessary to pass the namespace when you already told '@google-cloud/datastore' what your namespace is 2) It is inconsistent behavior since you don't really have to pass the namespace unless you get in this situation so prone to bugs.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Ok I understand you have several datastore instances running. I never had this situation as I only configure the datastore once when my server start.

By curiosity, what is your use case ? As for me the purpose of the namespace is mainly to differentiate the environments of the app. Another use case would be to have one namespace by "business client", then as it is dynamic, you can not create "instances" of datastore ahead... So I am curious :)

from gstore-node.

jainanshul avatar jainanshul commented on May 25, 2024

I have multiple namespaces to help isolate different sources/types of data. Each datastore instance is associated with a given namespace and was hoping I could use gstore-node instance per datastore client per namespace so rest of the code I have doesn't need to pass in the namespaces to interact with datastore and simply operates on a specific gstore instance.

Your suggestion above to pass in namespace works but I think having a global or a singleton instance of gstore-node when it is in fact wrapping a unique datastore instance is limiting. Not a big deal as I could work around it (thanks for your suggestion!)

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

I see. I will have a look into it. For now it needs to be singleton to ensure that Models are defined only once. That's why you can do this anywhere to retrieve a Model:

const gstore = require('gstore-node');
const MyModel = gstore.model('MyModel');

Having several instances would mean to store the Models differently.

from gstore-node.

6uliver avatar 6uliver commented on May 25, 2024

I did the same workaround, I'm passing in namespace parameter for some call.

I have another use case for namespaces: I have a legacy datastore schema and I'm migrating to a new schema. I've decided to separate the different versions with namespaces, v1, v1.1, v2 etc so we can use the old and new one at the same time without interference.

IMO this enhancement would help to write data migration code easier for our use case.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Thanks for the feedback. I will look into a solution for this.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hi,
I just released v2.0.0 that support multiple instances of gstore. I still have to update the docs but you can see how to do it in the release notes.
Let me know if there is any issue. thanks!

from gstore-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.