Hi,
I want to implement file tree structure in dgraph like this:
(:Folder)-[:IN_FOLDER]->(:Folder)
(:File)-[:IN_FOLDER]->(:Folder)
and query anything under a folder.
how should I consider schema and query?
Hi,
I want to implement file tree structure in dgraph like this:
(:Folder)-[:IN_FOLDER]->(:Folder)
(:File)-[:IN_FOLDER]->(:Folder)
and query anything under a folder.
how should I consider schema and query?
As it shows. But I’m changing the name “IN_FOLDER” to “N_FOLDER” (that would be “nested folder”)
schema
type Folder {
name
size
N_FOLDER
}
type File {
name
}
N_FOLDER: [uid] .
name: string .
size: int .
JSON format
[
{
"name@en": "some folder",
"size": "300MB",
"dgraph.type": "Folder",
"N_FOLDER": [
{
"name@en": "some folder",
"size": "100MB",
"dgraph.type": "Folder",
"N_FOLDER": [
{
"name@en": "some File",
"size": "100MB",
"dgraph.type": "File"
}
]
},
{
"name@en": "some File",
"size": "100MB",
"dgraph.type": "File"
}
]
}
]
Query
{
q(func: eq(name@en, "some folder")) @recurse {
name@en
N_FOLDER
size
}
}
thank you for replying,
I should save children ids under folder, right?
Can I have structure like this?
I want to normalize data as it’s possible
type Folder{
id
parentId (a folder)
name
}
type File {
id
parentId (a folder)
name
}
and query for folders and files that have the same parentId?
Not sure what you mean. Which Ids?
Here @normalize Directive - Query language
This isn’t necessary. Use reverse edges.
This parentId is a custom ID made by your side? You don’t need those, you can rely on Dgraph’s UIDs.