Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot provide my own id #2

Open
alblandino opened this issue Oct 31, 2017 · 5 comments
Open

Cannot provide my own id #2

alblandino opened this issue Oct 31, 2017 · 5 comments

Comments

@alblandino
Copy link

The structure you use to save the resources automatically generates an incremental ID, in which case you want to save this:

{
    id: 100,
    fname: "Joel",
    lname: "Jaime"
}

I simply omit the ID field since I would try to replace the one generated by lowdb-api.

One suggestion would be that instead of an incremental ID you generate a kind of {_id: guid_format} (or any unique data) or have the identifier inside protected object:

{
    core: {
        id : AUTOGENERATED_ID
    },
    fname: "Joel",
    lname: "Jaime"
}
@alblandino
Copy link
Author

Related with the PR #3

@rmariuzzo rmariuzzo changed the title Problem with ID field Cannot provide my own id Oct 31, 2017
@rmariuzzo
Copy link
Owner

@jblandino Do you think it is common to provide an ID on creation? If that's the case I'm open to consider allowing users to provide id on creation.

As you mentioned, I think it would be also good to allow user to provide a function for id generation. That way, user can opt-in for any kind of identity generator.

What are your thoughts?

@alblandino
Copy link
Author

alblandino commented Oct 31, 2017

Hi @rmariuzzo.

Well if you knew that when I implemented it in a project that I currently have, the first thing I did was send some session data to see how I could store them temporarily but send these fields:

{ id: Number, _token: String, date: Date }

The ID is a value that I generate in my own application and for me that field is mandatory, it happens that when I save it I realize that lowdb replaces it with its own identifier automatically.

This need was that it led me to think that it would be good to leave the resource identifier outside the object where the user's data is stored.

Note: in this issue I put a different structure to the one I have in the PR, this is because I found the PR form at the last moment and I consider it more feasible.

@rmariuzzo
Copy link
Owner

@jblandino in that case I'm willing to allow user to provide their id. The flow will be:

  1. user post data.
  2. if the posted data contains id use it, otherwise use generator.
  3. persist posted data.

What do you think? I'm open to suggestions.

@alblandino
Copy link
Author

Perfect @rmariuzzo , if the user passes his own ID he could use it and in case he does not pass it then the autogenerate is used, I see it well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants