Coder Social home page Coder Social logo

Comments (8)

ttu avatar ttu commented on June 8, 2024 2

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.

from json-flatfile-datastore.

AbdulmueezEmiola avatar AbdulmueezEmiola commented on June 8, 2024 1

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

from json-flatfile-datastore.

ttu avatar ttu commented on June 8, 2024

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"
  }
}

from json-flatfile-datastore.

Deilan avatar Deilan commented on June 8, 2024

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

from json-flatfile-datastore.

ttu avatar ttu commented on June 8, 2024

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

from json-flatfile-datastore.

Deilan avatar Deilan commented on June 8, 2024

@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.

from json-flatfile-datastore.

ttu avatar ttu commented on June 8, 2024

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

from json-flatfile-datastore.

MostHated avatar MostHated commented on June 8, 2024

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. : /

from json-flatfile-datastore.

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.