Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8eff7fcddd
Fetching contributors…

Cannot retrieve contributors at this time

file 105 lines (86 sloc) 2.367 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
http = require('http')
fs = require('fs')
async = require('async')
Data = require('data')
_ = require('underscore')

global.config = JSON.parse(fs.readFileSync(__dirname+ '/config.json', 'utf-8'))
global.seed = JSON.parse(fs.readFileSync(__dirname+ '/db/schema.json', 'utf-8'))

graph = new Data.Graph(seed, false)

graph.connect('couch', {
  url: config.couchdb_url
})

graph.sync( (err) ->
    if (!err)
        console.log('Successfully synced')
    else
        console.log('error')
        console.log( err )
)

console.log( 'types:' )
console.log( graph.types().data )

console.log( 'objects:' )
console.log( graph.objects() )

graph.bind('dirty', ->
  graph.sync( (err, invalidNodes) ->
    if( !err )
        console.log('Successfully synced:')
    else
        console.log('error:')
        console.log( err )
        console.log( invalidNodes )
    console.log( 'new graph:' )
    console.log( graph.objects().data )
  )
)

console.log( 'adding /card/teambuy' )
graph.set(
  _id: "/card/teambuy"
  type: "/type/card"
  fn: "TeamBuy"
)

console.log( 'adding /listing/teambuy_28133394' )
graph.set(
  _id: "/listing/teambuy_28133394"
  type: "/type/listing"
  item_info: "Textbook Rental"
  lister: "/card/teambuy"
)

console.log( 'dirty:' )
console.log( graph.dirtyNodes().data )

console.log( 'invalid:' )
console.log( graph.invalidNodes() )

console.log( 'conflicted:' )
console.log( graph.conflictedNodes() )

console.log( 'rejected:' )
console.log( graph.rejectedNodes() )

#graph.merge( seed, { dirty: true } )
###
graph.sync( (err) ->
if (!err)
console.log('Successfully synced')
else
console.log('error')
console.log( err )

graph.set(
_id: "/card/wagjag"
type: "/type/card"
fn: "wagjag"
)

old_value = graph.get( '/listing/teambuy_28133394' )
console.log( old_value.get( 'lister' ).get( 'item_info' ) )
graph.get( '/listing/teambuy_28133394' ).set(
lister: "/card/wagjag"
)

console.log( graph.get( "/card/teambuy" ) )

#graph.merge( seed, { dirty: true } )
graph.sync( (err) ->
if (!err)
console.log('Successfully synced')
else
console.log('error')
console.log( err )

new_value = graph.get( "/listing/teambuy_28133394" )
#console.log( new_value.get( 'lister' ).get( 'fn' ) )
)
)
###
Something went wrong with that request. Please try again.