{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/13030","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/13030/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/13030/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/13030/events","html_url":"https://github.com/laravel/framework/pull/13030","id":146152396,"number":13030,"title":"[5.2] Allows developers to traverse their query result via a cursor","user":{"login":"kharysharpe","id":278654,"avatar_url":"https://avatars.githubusercontent.com/u/278654?v=3","gravatar_id":"","url":"https://api.github.com/users/kharysharpe","html_url":"https://github.com/kharysharpe","followers_url":"https://api.github.com/users/kharysharpe/followers","following_url":"https://api.github.com/users/kharysharpe/following{/other_user}","gists_url":"https://api.github.com/users/kharysharpe/gists{/gist_id}","starred_url":"https://api.github.com/users/kharysharpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kharysharpe/subscriptions","organizations_url":"https://api.github.com/users/kharysharpe/orgs","repos_url":"https://api.github.com/users/kharysharpe/repos","events_url":"https://api.github.com/users/kharysharpe/events{/privacy}","received_events_url":"https://api.github.com/users/kharysharpe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":39,"created_at":"2016-04-06T00:51:45Z","updated_at":"2016-07-22T19:27:05Z","closed_at":"2016-05-24T15:49:27Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/13030","html_url":"https://github.com/laravel/framework/pull/13030","diff_url":"https://github.com/laravel/framework/pull/13030.diff","patch_url":"https://github.com/laravel/framework/pull/13030.patch"},"body":"Ran into an issue with attempting to use chunk wherein the underlining database would change and therefore the data would no longer be as initially requested. It is also generated a query for every chuck it returns.\r\n\r\nTraditionally in php we would do something like below, but I found no Eloquent equivalent.\r\n\r\n```\r\n    while ($row = $stmt->fetch(PDO::FETCH_NUM)) {\r\n      $data = $row[0] . \"\\t\" . $row[1] . \"\\t\" . $row[2] . \"\\n\";\r\n      print $data;\r\n    }\r\n\r\n```\r\n\r\n* Efficiently process thousands of records, uses memory efficiently.\r\n* Hits the database once with single query with local and global scopes.\r\n* Allows you to use a cursor to process the result set.\r\n\r\nUsage:\r\n\r\n```\r\nforeach(Flight::where('foo', 'bar')->cursor() as $model) {\r\n\r\n    //Do something complex with each $model\r\n\r\n};\r\n```\r\n\r\nUpdate: Using generator instead of callback\r\nUpdate: Using Eloquent model and changed name to cursor"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/234634011","html_url":"https://github.com/laravel/framework/pull/13030#issuecomment-234634011","issue_url":"https://api.github.com/repos/laravel/framework/issues/13030","id":234634011,"user":{"login":"nerdo","id":1031502,"avatar_url":"https://avatars.githubusercontent.com/u/1031502?v=3","gravatar_id":"","url":"https://api.github.com/users/nerdo","html_url":"https://github.com/nerdo","followers_url":"https://api.github.com/users/nerdo/followers","following_url":"https://api.github.com/users/nerdo/following{/other_user}","gists_url":"https://api.github.com/users/nerdo/gists{/gist_id}","starred_url":"https://api.github.com/users/nerdo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nerdo/subscriptions","organizations_url":"https://api.github.com/users/nerdo/orgs","repos_url":"https://api.github.com/users/nerdo/repos","events_url":"https://api.github.com/users/nerdo/events{/privacy}","received_events_url":"https://api.github.com/users/nerdo/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T19:27:05Z","updated_at":"2016-07-22T19:27:05Z","body":"+1, but generate() makes more sense to me than cursor(), as it more clearly describes what is happening under the hood at the PHP level and maintains a level of abstraction with the concept of a true DB cursor, which this isn't AFAIK."}}
{"actor":{"display_login":"nerdo"}}