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

How to get whole document? #19

Open
Deilan opened this issue Aug 7, 2018 · 8 comments · May be fixed by #64
Open

How to get whole document? #19

Deilan opened this issue Aug 7, 2018 · 8 comments · May be fixed by #64

Comments

@Deilan
Copy link

Deilan commented Aug 7, 2018

Is there a way to retrieve a whole document, not just some of it's properties or collections?

For a json file from a docs' sample:

{
  "selected_user": { "id": 1, "name": "Phil", "age": 40, "city": "NY" },
  "temperature": 23.45,
  "note": "this is a test"
}

How could one retrieve it a as a whole into an instance of a class?

public class Settings
{
    public User SelectedUser { get; set; }
    public double Temperature { get; set; }
    public string Note { get; set; }
}
@Deilan Deilan changed the title How to get whole document How to get whole document? Aug 7, 2018
@ttu
Copy link
Owner

ttu commented Aug 8, 2018

There is no way to retrieve whole JSON as a document/object.

Root level properties are documents, so if you want to retrieve settings as a single object, you have to put it under property:

{
  "settings" : { 
    "selected_user": { "id": 1, "name": "Phil", "age": 40, "city": "NY" },
    "temperature": 23.45,
    "note": "this is a test"
  }
}

@Deilan
Copy link
Author

Deilan commented Aug 8, 2018

@ttu Thanks for the response! May I request a feature to retrieve a whole document then? :)

@ttu
Copy link
Owner

ttu commented Aug 9, 2018

Yes, I can add it.

How about if I just modify the GetItem-method, so if it is called with empty string as a key, then it would return the whole JSON?

var settings = _ds.GetITem<Settings>(string.Empty);

@Deilan
Copy link
Author

Deilan commented Aug 12, 2018

@ttu There are 3 points why I think it should be done in a different way:

  1. "" (empty string) - is a valid JSON token's name. In other words { "": 0 } is a valid JSON. Hence we have an ambiguation between retrieving "" property and the whole document. Besides it could break backward compatibility.
  2. From the method's name it's unclear that it could be used to retrieve the whole document - by using special values or without them.
  3. From my point of view It violates SRP: the method is being utilized for two distinct things.

I'd say there should be a dedicated method for getting the whole document. Something like GetRoot or GetDocument. GetRoot seems more appropriate to me because at the outermost level JSON could be an array as well as an object.

@ttu
Copy link
Owner

ttu commented Aug 13, 2018

Thanks for the input and yes, you are correct.

First I was thinking also GetRoot-method, but because of lack of time, thought that adding functionality to GetItem would have been the fastest way to implement this. As you pointed out, it wouldn't have even worked that way.

Have to think this littlebit more, but maybe GetRoot has to return Root-object that can either have a DocumentCollection or a single item.

@ttu ttu added the help wanted label Mar 4, 2019
@AbdulmueezEmiola
Copy link

Hello,
I saw this issue opened and I was wondering whether It has been fixed. If not, I will like to attempt to provide a solution to it

@ttu
Copy link
Owner

ttu commented Aug 30, 2020

Thanks @AbdulmueezEmiola! This hasn't been fixed/implemented yet. I started some solution, but then forgot this...

Pushed the implementation I had done to https://github.com/ttu/json-flatfile-datastore/tree/add-getroot. Commit: 0258e7e

Based on what you had in mind you can continue that or if you have some better idea, provide a new solution :)

@MostHated
Copy link

If someone does provide a solution for this, it would be appreciated if this could be updated. I just started using this today, got it all worked out and implemented, only to find out I could not simply get all records. : /

colbytimm added a commit to colbytimm/json-flatfile-datastore that referenced this issue Feb 21, 2022
colbytimm added a commit to colbytimm/json-flatfile-datastore that referenced this issue Feb 21, 2022
@colbytimm colbytimm linked a pull request Feb 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants