Comments (3)
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.
Looking at my original entry a bit more closely, I guess there are two levels to this:
- Regardless, maybe an exception shouldn't be thrown here, at least?
- 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.
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)
- pull-report
- Recursive unions HOT 4
- Data loss in p/add with nested maps HOT 2
- `lambdaisland/uri` HOT 1
- Reverse order for lists? HOT 6
- Return indices in pull report
- add-report HOT 1
- Relax requirement for collections with lookup refs to be homogeneous HOT 1
- Replacing an entity using `delete` and `add` throws exception if entity does not exist HOT 2
- Dynamic map keys HOT 1
- Delete HOT 1
- Plans for supporting wild card for pulls? HOT 9
- Infer EQL query from data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyramid.