{"action":"created","issue":{"url":"https://api.github.com/repos/ccgus/fmdb/issues/167","labels_url":"https://api.github.com/repos/ccgus/fmdb/issues/167/labels{/name}","comments_url":"https://api.github.com/repos/ccgus/fmdb/issues/167/comments","events_url":"https://api.github.com/repos/ccgus/fmdb/issues/167/events","html_url":"https://github.com/ccgus/fmdb/issues/167","id":17135790,"number":167,"title":"Passing a FMResultSetterMapper to a query so the result is mapped onto an object. ","user":{"login":"jasperblues","id":430321,"avatar_url":"https://avatars.githubusercontent.com/u/430321?v=3","gravatar_id":"","url":"https://api.github.com/users/jasperblues","html_url":"https://github.com/jasperblues","followers_url":"https://api.github.com/users/jasperblues/followers","following_url":"https://api.github.com/users/jasperblues/following{/other_user}","gists_url":"https://api.github.com/users/jasperblues/gists{/gist_id}","starred_url":"https://api.github.com/users/jasperblues/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasperblues/subscriptions","organizations_url":"https://api.github.com/users/jasperblues/orgs","repos_url":"https://api.github.com/users/jasperblues/repos","events_url":"https://api.github.com/users/jasperblues/events{/privacy}","received_events_url":"https://api.github.com/users/jasperblues/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2013-07-24T01:52:20Z","updated_at":"2015-03-31T10:53:53Z","closed_at":null,"body":"How about .  . .\r\n\r\nPassing a FMResultSetterMapper to a query so the result is mapped onto an object?\r\n\r\n. . . . similar to SpringJDBC"},"comment":{"url":"https://api.github.com/repos/ccgus/fmdb/issues/comments/88041320","html_url":"https://github.com/ccgus/fmdb/issues/167#issuecomment-88041320","issue_url":"https://api.github.com/repos/ccgus/fmdb/issues/167","id":88041320,"user":{"login":"jasperblues","id":430321,"avatar_url":"https://avatars.githubusercontent.com/u/430321?v=3","gravatar_id":"","url":"https://api.github.com/users/jasperblues","html_url":"https://github.com/jasperblues","followers_url":"https://api.github.com/users/jasperblues/followers","following_url":"https://api.github.com/users/jasperblues/following{/other_user}","gists_url":"https://api.github.com/users/jasperblues/gists{/gist_id}","starred_url":"https://api.github.com/users/jasperblues/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasperblues/subscriptions","organizations_url":"https://api.github.com/users/jasperblues/orgs","repos_url":"https://api.github.com/users/jasperblues/repos","events_url":"https://api.github.com/users/jasperblues/events{/privacy}","received_events_url":"https://api.github.com/users/jasperblues/received_events","type":"User","site_admin":false},"created_at":"2015-03-31T10:53:53Z","updated_at":"2015-03-31T10:53:53Z","body":"By adding the following: \r\n\r\n```objc\r\n/**\r\n* Iterates over the result set mapping each row onto a domain entity type.\r\n*/\r\n@protocol FMRowMapper<NSObject>\r\n\r\n- (id)mapRow:(NSUInteger)rowNumber inResultSet:(FMResultSet *)resultSet;\r\n\r\n@end\r\n/**\r\n* Maps the entire result set onto an arbitrary object. Unlike FMRowMapper it is necessary to iterate over the result set\r\n* whereas FMRowMapper provides an interface for mapping a single row to a domain model object, therefore FMRowMapper\r\n* is generally the simpler choice. FMResultSetExtractor is useful for example to map a one-to-many using a single SQL\r\n* query.\r\n*/\r\n@protocol FMResultSetExtractor<NSObject>\r\n\r\n- (id)extractData:(FMResultSet *)resultSet;\r\n\r\n@end\r\n```\r\n\r\nI was could define the following category methods on `FMResultSet`\r\n\r\n```objc\r\n/**\r\n* Returns an array where for each item in the result set, iterates mapping each row onto a domain entity type.\r\n*\r\n* The result set is closed upon completion.\r\n*/\r\n- (NSArray *)mapWith:(id<FMRowMapper>)mapper;\r\n\r\n/**\r\n* Maps the entire result set onto an arbitrary object. Unlike FMRowMapper it is necessary to iterate over the result set\r\n* whereas FMRowMapper provides an interface for mapping a single row to a domain model object, therefore FMRowMapper\r\n* is generally the simpler choice. FMResultSetExtractor is useful for example to map a one-to-many using a single SQL\r\n* query.\r\n*\r\n* The result set is closed upon completion.\r\n*/\r\n- (id)extractWith:(id<FMResultSetExtractor>)extractor;\r\n\r\n@end\r\n```\r\n\r\nThis simplifies the implementation of DAO (data access object classes somewhat): \r\n\r\n```objc\r\n- (NSArray *)listAll\r\n{\r\n    NSString *select = @\"SELECT * FROM OFFER\";\r\n\r\n    __block NSArray *offers = nil;\r\n    [_queue inDatabase:^(FMDatabase *database) {\r\n        FMResultSet *resultSet = [database executeQuery:select];\r\n        offers = [resultSet mapWith:self];\r\n    }];\r\n    return offers;\r\n}\r\n```\r\n\r\nI think this is of general utility, hence sending PR. "}}