Code Monkey home page Code Monkey logo

Comments (3)

lilactown avatar lilactown commented on September 27, 2024

This will work if you tweak the second example a bit - instead of passing in vectors as references, if you change them to maps, it will work:

(def db (p/db [{:id   0
                :refs [{:id 1} {:id 2}]}
                {:id    1
                 :hello :world}]))

(p/pull db [{[:id 0]
             [{:refs [:id :hello]}]}])
;; => {[:id 0] {:refs [{:id 1, :hello :world} {:id 2}]}}

In general you can think of the operations like: add takes entities and returns data full of references, and pull takes data full of references and resolves entities. In the original, you're short circuiting the entity processing that add does.

My next thought is that when an entity doesn't exist in the db, to return something, which I guess gets to your ask- should a ref to an entity that doesn't exist return a minimal map {:id 2}, or nothing?

For my own uses, I think that eliding [:id 2] from the result in the original would be better. It means that if I dissoc an entity from the db, that dangling references aren't going to return incomplete data that I'll have to code defensively against. What do you think, in the context of the above solution (passing in maps for the refs when adding)?

Also, thank you for all the work you're doing to report these corners, @eneroth ! I really appreciate it. I hope that we can fine tune pyramid to work better for you.

from pyramid.

eneroth avatar eneroth commented on September 27, 2024

Looking at my original entry a bit more closely, I guess there are two levels to this:

  1. Regardless, maybe an exception shouldn't be thrown here, at least?
  2. If it's a dangling ident, should it be considered "not there"?

With regards to 2, my feeling is that by passing it in, I have effectively stated "there's something here, but I don't know much about it." Yeah, maybe the correct idea is that it should be turned into into a map then (I was hoping to avoid this, since it requires walking the entire structure, looking for idents, which I know that Pyramid will have to do againโ€”feels wasteful).

With regards to eliding the value: my thinking here is formed from having worked with Fulcro, in which you're very much encouraged (primarily through helpers) to remove the entity and it's reference. I.e., the DB doesn't contain anything that's open to interpretation, or could be considered "broken". In Fulcro, just dissocing an entity without cleaning up its references would be considered kind of sloppy, I think :)

To be clear @lilactown, Pyramid already works great! I'm so happy to have something framework-agnostic that provides this functionality, and can be used more ad-hoc than a fullblown DB (even an in-memory one).

from pyramid.

lilactown avatar lilactown commented on September 27, 2024

yeah, there is a pyramid.core/delete fn which should handle it for you.

Fixed this in 94d2131. Now it should return a map {:id 2} when querying.

from pyramid.

Related Issues (14)

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.