Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Use commits to store network diff todo/redo #128

Open
clemsos opened this issue Aug 8, 2016 · 2 comments
Open

Use commits to store network diff todo/redo #128

clemsos opened this issue Aug 8, 2016 · 2 comments

Comments

@clemsos
Copy link
Member

clemsos commented Aug 8, 2016

Thinking about an implementation for the query language (see #127), it will be easier to store things in the form of transactions instead of having plain data stored directly in mongo. That way we can also redo / undo super easily (will fix #51)

The basic idea is that all actions are described internally as instructions with a super basic query language

const instructions  = [
    {
      action : 'ADD', 
      type : 'nodes',
      elements : [
        { 'id' : '1', 'name' : 'A'}, 
        { 'id' : '2', 'name' : 'B'}, 
        { 'id' : '3', 'name' : 'C'}
      ]
    },
    {
      action : 'ADD', 
      type : 'edges',
      elements : [
        { 'id' : 'edgeA', 'source' : '1', 'target' : '2'},
        { 'id' : 'edgeB', 'source' : '1', 'target' : '3'}, 
        { 'id' : 'edgeC', 'source' : '2', 'target' : '3'}
      ]
    },
    {
      action : 'DELETE',
      elements : [
        'edgeB'
      ],
      type : 'edges'
    },  
    {
      action : 'ADD',  
      elements : [
        { 'id' : 'edgeD', 'source' : '3', 'target' : '2'},
        { 'id' : 'edgeE','source' : '5', 'target' : '3'} 
      ],
      type : 'edges' 
    },  
    {
      action : 'DELETE',
      elements : ['1'],
      type : 'nodes' 
    }, 
    {
      action : 'ADD',
      elements  : [
        '4', 
        '5', 
        '6'
      ],
      type: 'nodes' 
    },
    {
      action : 'UPDATE',
      elements : [
        { 'ids' : ['2'],  'updates' : { 'name' : 'yeepeeee!' } }
      ],
      type: 'nodes' 
    }
]

Then we can easily to this actions into a commit with a unique hash/id which will store the diff

let diff =  {
      nodes : {
        add : [],
        update : [],
        delete : []
      }, 
      edges : {
        add : [],
        update : [],
        delete : []
      }
    }

We can serialize this commit (id+diff) into the db, so it will become easier to have migrations undo/redo in the db and keep track of the changes in the network.

Here is a working example for the commit : https://jsbin.com/xeriba/710/edit?js,console,output

@clemsos
Copy link
Member Author

clemsos commented Aug 11, 2016

Here is the general data /commit structure https://github.com/topogram/topoquery

@clemsos
Copy link
Member Author

clemsos commented Oct 27, 2017

A better solution to store graph as events : https://github.com/clemsos/graph-events

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

1 participant