uMaxmaxmaximus / ui-js

6 stars 4 forks source link

ormjs: Edge collection modelling #4

Open OKNoah opened 7 years ago

OKNoah commented 7 years ago

Hi, I'd like to work a bit on this package. I've forked it at https://github.com/OKNoah/ormjs.

I'm pretty new to ArangoDB.

I'd like to try add support for modelling edge collections. I believe this is done by var actsIn = db._createEdgeCollection("actsIn"); in the javascript driver, as seen here: https://github.com/arangodb/Cookbook/blob/master/recipes/Graph/ExampleActorsAndMovies.md

I'm just thinking of the syntax now. Open to suggestions. Perhaps like this.

import Model, { Edge } from './db'

/* A User lives at an Address */
export default class LivesAt extends Edge {
  static schema = {
    created: Date
  }
}

export default class User extends Model {
  static schema = {
    name: String,
    created: Date
  }
}

export default class Address extends Model {
  static schema = {
    street: String,
    city: String
  }
}

const user = await User.add({
  name: 'Will',
  created: Date()
})

const address = await Address.add({
  city: 'Bel Air'
})

const relationship = await LivesAt.add(user, address)

user.save()
address.save()
relationship.save()
OKNoah commented 7 years ago

This has been added here in my fork: https://github.com/OKNoah/ormjs/commit/3f3c81a1215fb8f705f03a5e97833153c9ab6b37

OKNoah commented 7 years ago

@MegaUITeam Good point, but not all associates will be edge collections, they might just be sub-docs. So there might have to be an option like { user: User, edge: true }.

OKNoah commented 7 years ago

@MegaUITeam Also, edge collections can have their own fields, so there needs to be a way to define those. And a name could be helpful cause there can be multiple edges for different purposes, I think.

User/Noah -> Loves -> User/Rose
User/Rose -> Blocks -> User/Noah