Comments (9)
I'm going to write an example today 👍
from neo4-js.
This actually needed a little more than just writing an example. I built a workaround into neo4js, have a look at https://neo4.js.org/docs/vanilla-node-guide.html on how to use neo4js without decorators. You'll need to update your neo4js dependency. I'm not a fan of it, but it works, let me know what you think about it and feel free to reopen this issue if you have any troubles with it!
from neo4-js.
Yeah, I definitely see how that looks nicer with decorators. The model
one seems the best because it almost reads to me as connect(User, UserInstance)
. The other ones are harder to reason about, but not completely unusable.
from neo4-js.
Maybe I'll rename this things! I already thought about connect. I think I could also give the relation "connect" the same name instead of two different (src, dest).
from neo4-js.
Yeah, maybe something like connect(User, '[tasks]').to(Task).via('created')
(where the brackets around "tasks" indicate the "many" part . . . other ways of expressing many are possible too, this was just the first that occurred to me).
from neo4-js.
If you can't tell, I'm a fan of the "fluent" chaining syntax . . . :)
from neo4-js.
This (connect(User, '[tasks]').to(Task).via('created')
) won't work because I need to know on which property of the ModelInstance I need to add the relation methods. Thus I went with decorators to connect the ModelInstance class properties to the desired relation like this:
const UserProjectRelation = relation("assigned")
.src.hasMany(Project)
.dest.hasMany(User);
@model(User)
class UserInstance extends ModelInstance<UserProps> {
@src(UserProjectRelation)
projects: HasManyActions<ProjectProps, ProjectInstance>;
}
But when I look at this, I only need to add the class properties directly to the declaration of the relation itself like this:
relation(Project, "assignedUsers")
.via("assigned")
.hasMany(User, "projects");
Which will create the relation methods on <ProjectInstance>.assignedUsers
and <UserInstance>.projects
. With that I would only need to use connect(Model, ModelInstance)
and we are all set 👍 . The order wether you write via
or hasMany/hasOne
after relation()
shouldn't matter. As it also doesn't matter with the current implementation of .src
and .dest
.
I think the keyword connect
would also make sense in this case like the following:
connect(Project, "assignedUsers")
.via("assigned")
.hasMany(User, "projects");
This is actually less code and better readable, at least in my mind :P
In fact the only reason I didn't do that in the first place is, that I wouldn't get any type hints from flow. So I went with decorators, which are slightly more complicated to reason about the relation.
I think I'll change the API for the non-decorator and non-flow approach to that. What do you think about that? Also we should either change the title of this issue or move this discussion to a new issue.
from neo4-js.
Yeah, I like that pretty well. It does seem like a different issue though, especially since you've already added a non-decorator example, which satisfies this issue.
from neo4-js.
Well, let's move it to a new issue then :)
from neo4-js.
Related Issues (5)
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 neo4-js.