{"action":"created","issue":{"url":"https://api.github.com/repos/spider/spider/issues/53","labels_url":"https://api.github.com/repos/spider/spider/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/spider/spider/issues/53/comments","events_url":"https://api.github.com/repos/spider/spider/issues/53/events","html_url":"https://github.com/spider/spider/issues/53","id":101483087,"number":53,"title":"Builder and Query Responsibilities","user":{"login":"chrismichaels84","id":5412413,"avatar_url":"https://avatars.githubusercontent.com/u/5412413?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismichaels84","html_url":"https://github.com/chrismichaels84","followers_url":"https://api.github.com/users/chrismichaels84/followers","following_url":"https://api.github.com/users/chrismichaels84/following{/other_user}","gists_url":"https://api.github.com/users/chrismichaels84/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismichaels84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismichaels84/subscriptions","organizations_url":"https://api.github.com/users/chrismichaels84/orgs","repos_url":"https://api.github.com/users/chrismichaels84/repos","events_url":"https://api.github.com/users/chrismichaels84/events{/privacy}","received_events_url":"https://api.github.com/users/chrismichaels84/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spider/spider/labels/discussion","name":"discussion","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/spider/spider/milestones/2","html_url":"https://github.com/spider/spider/milestones/v0.4%20-%20Full%20Command%20Builder","labels_url":"https://api.github.com/repos/spider/spider/milestones/2/labels","id":1219151,"number":2,"title":"v0.4 - Full Command Builder","description":"The Full Command Builder extends the Basic Command Builder by adding declarative traversals, nested queries, and a solution for the n+1 problem (building a query that fetches a post with all its comments in one query).\r\n\r\nThe Full Command Builder also introduces that the user can specify how they want the result formatted (e.g. `tree`, `flat`, etc).\r\n\r\nLay foundation for Models/Graphs\r\n\r\nTop-level Spider\\Spider Api","creator":{"login":"chrismichaels84","id":5412413,"avatar_url":"https://avatars.githubusercontent.com/u/5412413?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismichaels84","html_url":"https://github.com/chrismichaels84","followers_url":"https://api.github.com/users/chrismichaels84/followers","following_url":"https://api.github.com/users/chrismichaels84/following{/other_user}","gists_url":"https://api.github.com/users/chrismichaels84/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismichaels84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismichaels84/subscriptions","organizations_url":"https://api.github.com/users/chrismichaels84/orgs","repos_url":"https://api.github.com/users/chrismichaels84/repos","events_url":"https://api.github.com/users/chrismichaels84/events{/privacy}","received_events_url":"https://api.github.com/users/chrismichaels84/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":2,"state":"open","created_at":"2015-07-21T21:32:06Z","updated_at":"2015-08-31T20:33:54Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-08-17T18:36:59Z","updated_at":"2015-08-31T21:57:28Z","closed_at":null,"body":"A recap of the conversation started in #22:\r\n________________\r\n*@PommeVerte* Aaaaaand while I'm at it. I've been thinking that we should provide a `TraversalBuilder` that extends `BaseBuilder` with a traversal syntax. I know we originally wanted to add sugar to Builder for this but thinking about it, it will be too complicated to do something clean (overlap and conflicts between what some methods would do). I have a couple of ideas here as well.\r\n________________\r\n*@chrismichaels84* Oh I didn't think about `Query`. `Builder` and `TraversalBuilder` would have been two leaves (it's not possible to have it function properly any other way as all the methods would function differently in populating the Bag) so maybe that would imply a different Query class as well.\r\n\r\nI'd much rather add the basic traversal features to `BaseBuilder` so it can:\r\n  1. CRUD vertices and edges with labels and types (already implemented)\r\n  1. Manage relationships between vertices (`$builder->addEdge($from, $two, $label, $properties` or something)\r\n  1. Perform basic relationship queries (get all friends of user 3 who have been friends more than 2 years, or get all posts tagged as new and important, etc.)\r\n  1. Perform powerful, if verbose queries, sub queries, and traversals.\r\n________________\r\n*@PommeVerte* I think a lot of what you mention would probably be better on the `Model` layer. It's an abstraction on the logic (query construction) and not really query sugar. \r\n\r\nAlso all methods would conflict.\r\n```php\r\n$builder->out()->out()->where().\r\n````\r\nThe `where` here would have to function completely differently to the current where that just adds stuff to the bag since this where would need to apply to some sub query. Actually a lot would have to be happening in the above. Anywho I don't see a `where()` or many other methods working for both scenarios.\r\nAlso what happens if you use `out()` in a declarative scenario? Sounds like a headache waiting to happen. I don't think there's much harm in providing two builders, two queries is a bit more of an issue though.\r\n________________\r\n*@chrismichaels84* I don't mind two builders. Its the two queries that rub me the wrong way. It complicates things for the user having to choose between or carry two different objects around in their code. This may be simplified in the top level api like\r\n```php\r\n$spider->traverse($start)->out()->out()->with();\r\n$spider->query()->select()->from();\r\n```\r\nBut that still seems unwieldy.\r\n\r\nHaving two builders also makes it difficult for a higher abstraction (model) to know which builder to use without being explicitly told. At the end of the day (top-level), the user shouldn't have to make that choice. They should declare what they want from a `model` or `spider` and it happens.\r\n\r\nIf we use subselects (as orient sql does), then most of the above is possible (with the exception, maybe, of number 4. I'd have to ask around).\r\n________________"},"comment":{"url":"https://api.github.com/repos/spider/spider/issues/comments/136512397","html_url":"https://github.com/spider/spider/issues/53#issuecomment-136512397","issue_url":"https://api.github.com/repos/spider/spider/issues/53","id":136512397,"user":{"login":"chrismichaels84","id":5412413,"avatar_url":"https://avatars.githubusercontent.com/u/5412413?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismichaels84","html_url":"https://github.com/chrismichaels84","followers_url":"https://api.github.com/users/chrismichaels84/followers","following_url":"https://api.github.com/users/chrismichaels84/following{/other_user}","gists_url":"https://api.github.com/users/chrismichaels84/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismichaels84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismichaels84/subscriptions","organizations_url":"https://api.github.com/users/chrismichaels84/orgs","repos_url":"https://api.github.com/users/chrismichaels84/repos","events_url":"https://api.github.com/users/chrismichaels84/events{/privacy}","received_events_url":"https://api.github.com/users/chrismichaels84/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T21:57:28Z","updated_at":"2015-08-31T21:57:28Z","body":"So, it occurred to me that we may be using terminology a little differently. I wanted to clear up my thoughts on a few things concerning relationships, traversals, and queries.\r\n\r\nIt may be best to speak of three distinct (though related) things:\r\n   1. *CRUD operations* are what are completed now. Create, retrieve, update, and drop vertices. Allows for complex queries, but only on vertices.\r\n   1. *Relationship Management* adds the ability to connect two (or more) vertices by edges. Also allows for querying based on simple relationships (get all users who have an outgoing relationship 'follows') . Not sure to what extend this piece does complex querying. Its primary responsibility is to CRUD edges.\r\n   1. *Traversals* are for complex querying, and querying *only*. Finding paths, distances, depths, etc.\r\n\r\nSome general thoughts about the above:\r\n  * That said, I think a sub-object for traversals may be a good idea. So that `$query->traverse()` allows for a different api for complex traversals.\r\n  * Relationship management should be handled by `BaseBuilder` with methods like `createEdge()`, `updateEdge()`, and `dropEdge()`.\r\n  * Also, in `BaseBuilder` add logic to basic where constraints to do simple querying based on edges.\r\n\r\nI am going to simplify the where mechanism in the base builder, moving a lot of the logic to `Builder`. So, `BaseBuilder` will only accept an array of arrays, each constraint being fully detailed, using constants and not aliases. `where([['username', Bag::EQUALS, $value, Bag::CONJUCTION]]);`\r\n\r\nThoughts?\r\n\r\n"}}