Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

How to manage edges in a node structure? #41

Open
josebalius opened this issue Oct 15, 2015 · 1 comment
Open

How to manage edges in a node structure? #41

josebalius opened this issue Oct 15, 2015 · 1 comment

Comments

@josebalius
Copy link

Lets say I have two nodes and I want to keep a relationship between these two nodes. Is there anyway I can model that in a struct? For example:

type Node struct {
   Type string
   InEdges []Edge
   OutEdges []Edge
}

type Edge struct {
   Source string // string for Node id, or actual Node ?
   Target string
   Weight int
}

My question is, is there anyway to use Orient's native edges and graph features but still be able to model them with structs?

@dennwc
Copy link
Collaborator

dennwc commented Oct 16, 2015

I'm afraid that there is no way to achieve it with structs only. But there is a few options:

  1. You can modify you SELECT statement and add an additional return value with a linked node using TRAVERSE or in/out() keywords and then load them into a struct.

  2. You can query you node with any method you want, and add a fields with mapstructure:"E_in" or mapstructure:"E_out", there E stands for relation type. This field must be of []OIdentifiable type (or []RID).

I'll think of a way to implement this behavior. But it can only be optional, because driver will have to fetch all linked nodes. If you have a node with thousands of relations this can be a problem :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants