{"action":"opened","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/3096","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3096/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3096/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3096/events","html_url":"https://github.com/realm/realm-cocoa/issues/3096","id":126360753,"number":3096,"title":"Sqlite3 to Realm convert.","user":{"login":"anandkumarsharma","id":10652590,"avatar_url":"https://avatars.githubusercontent.com/u/10652590?v=3","gravatar_id":"","url":"https://api.github.com/users/anandkumarsharma","html_url":"https://github.com/anandkumarsharma","followers_url":"https://api.github.com/users/anandkumarsharma/followers","following_url":"https://api.github.com/users/anandkumarsharma/following{/other_user}","gists_url":"https://api.github.com/users/anandkumarsharma/gists{/gist_id}","starred_url":"https://api.github.com/users/anandkumarsharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anandkumarsharma/subscriptions","organizations_url":"https://api.github.com/users/anandkumarsharma/orgs","repos_url":"https://api.github.com/users/anandkumarsharma/repos","events_url":"https://api.github.com/users/anandkumarsharma/events{/privacy}","received_events_url":"https://api.github.com/users/anandkumarsharma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-13T07:38:21Z","updated_at":"2016-01-13T07:38:21Z","closed_at":null,"body":"Hello sir,\r\n\r\nI am converting sqlite3 into Realm.\r\nI am new to Realm, i would like to get count from  Realm model like below as sqlite3 code but i am not get success please help me.\r\n\r\nMy sqlite3 code are as follow:-\r\n\r\n\r\nDatabaseManager *dbManager = [DatabaseManager sharedManager];\r\n__block  NSUInteger counts;\r\n\r\n     [dbManager.databaseQueue inDatabase:^(FMDatabase *db)\r\n     {\r\n        counts = [db intForQuery:[NSString stringWithFormat:@\"SELECT COUNT(*) FROM  ContactCardTbl where\r\n                                                  contactCardId='%@'\", contactCardId]];\r\n      }];\r\n\r\n             [dbManager.databaseQueue inDatabase:^(FMDatabase *db)\r\n             {\r\n                 if (counts == 0)\r\n                 {\r\n                      [db executeUpdate:@\"INSERT INTO ContactCardTbl (contactCardId,userId,full_Name,changeId,json) values (?,?,?,?,?)\",contactCardId,userId,full_Name,changeId,json];\r\n                }\r\n                else\r\n                 {\r\n                    [db executeUpdate:@\"UPDATE ContactCardTbl SET userId = ?, full_Name = ?, changeId = ?, json = ? WHERE contactCardId = ?\", userId, full_Name, changeId, json, contactCardId];\r\n                 }\r\n            }];\r\n\r\n}\r\n\r\nI am converting this code in Realm as follows:\r\n\r\n RLMRealm *realm = [RLMRealm defaultRealm];\r\n            \r\n            //Begin a write transaction to save to the default Realm\r\n            [realm beginWriteTransaction];\r\n\r\n              contactModel *contactModelInformation = [[contactModel alloc]init];\r\n        \r\n             [contactModel objectsWhere:@\"contactModelInformation.@count\"];\r\n        \r\n              NSLog(@\"contactModel counts -----%@\", [contactModel objectsWhere:@\"contactModelInformation.@count\"]);\r\n        \r\n             contactModelInformation.contactCardId = [dictionary objectForKey:@\"contactCardId\"];\r\n             contactModelInformation.userId = [dictionary objectForKey:@\"userId\"]; \r\n             contactModelInformation.full_Name = [dictionary objectForKey:@\"full_Name\"];\r\n             contactModelInformation.changeId = [NSString stringWithFormat:@\"%@\",[dictionary objectForKey:@\"changeId\"]];\r\n\r\n            \r\n             NSData* jsonDataDic;\r\n             if ([dictionary isKindOfClass:[NSDictionary class]]) {\r\n               jsonDataDic = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];\r\n                 contactModelInformation.json = [[NSString alloc] initWithBytes:[jsonDataDic bytes] length:[jsonDataDic length] encoding:NSUTF8StringEncoding];\r\n            }\r\n            \r\n            //Add the loginInformation object to default Realm.\r\n             [realm addObject:contactModelInformation];\r\n        \r\n        \r\n            //Persist all the loginInformation that were persisted.\r\n             [realm commitWriteTransaction];\r\n            \r\n       // });\r\n    }\r\n\r\nbut i am not get success please help me how this realm code will be work as same as sqlite3 code of above.\r\n\r\nThanks,"}}