-
-
Save nikgraf/1031559 to your computer and use it in GitHub Desktop.
data.js playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Data = require('data') | |
schema = | |
'/type/project': | |
'type': 'type' | |
'name': 'Project' | |
'properties': | |
'name': | |
'name': 'Name', 'unique': true, 'type': 'string', 'required': true | |
'tags': | |
'name': 'Tag', 'unique': false, 'type': '/type/tag' | |
'/type/tag': | |
'type': 'type' | |
'name': 'Location' | |
'properties': | |
'name': | |
'name': 'Name', 'unique': true, 'type': 'string', 'required': true | |
'projects': | |
'name': 'Project', 'unique': false, 'type': '/type/project' | |
graph = new Data.Graph schema | |
graph.set("/project/a", | |
type: '/type/project' | |
name: 'a' | |
) | |
graph.set("/tag/ta", | |
type: '/type/tag' | |
name: 'ta' | |
projects: ['/project/a'] | |
) | |
# Reverse link! | |
graph.get("/project/a").set( | |
tags: ['/tag/ta'] | |
) | |
console.log graph.get('/tag/ta').toJSON() | |
console.log graph.get('/tag/ta').get('projects') | |
console.log graph.get('/tag/ta').get('projects').first() #.get('projects') | |
console.log graph.get('/project/a').get('name') # is 'a' as expected | |
console.log graph.get('/project/a').get('tags') # should be '/tag/ta' but is null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment