Skip to content

Instantly share code, notes, and snippets.

@nikgraf
Forked from michael/npm-graph
Created June 17, 2011 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikgraf/1031559 to your computer and use it in GitHub Desktop.
Save nikgraf/1031559 to your computer and use it in GitHub Desktop.
data.js playground
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