What is the best way to convert an existing Sqlite database to Realm? is there any tool or script for this?And my other question is: Does Realm compresses data? Is there any comparison regarding size of same data in Sqlite and Realm?
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-users...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-users/45efcf75-39b7-4dec-a5dc-9520ce67044d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
// Define your models
@interface Word : RLMObject
@property NSInteger _id;
@property NSString *word;
@property NSString *definition;
@end
@implementation Word
@end
RLM_ARRAY_TYPE(Word)
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
RLMRealm *realm = [RLMRealm defaultRealm];
NSString * path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"db"];
FMDatabase * db = [FMDatabase databaseWithPath:path];
[db open];
NSString * query = [NSString stringWithFormat:@"select * from Words"];
FMResultSet *s = [db executeQuery:query];
[realm beginWriteTransaction];
while ([s next]) {
Word * word = [[Word alloc] init];
word._id = [s intForColumn:@"_id"];
word.word = [s stringForColumn:@"word"];
word.definition = [s stringForColumn:@"explanation"];
[realm addObject:word];
}
[realm commitWriteTransaction];
NSLog(@"done");
RLMArray *words = [Word objectsWhere:@"_id = 203"];
NSLog(@"%@", words);
return YES;
}
Hi Abbas, there's no tool to automatically convert a SQLite database to Realm, but we do plan on releasing such a tool in the near future.In the meantime, you could easily adapt the RealmJSONImportExample to read from a SQLite database instead of a JSON file.And Realm doesn't compress its data, which would require additional CPU time, power and disk space. However, Realm leverages bit-packing and smart column optimizations to be generally ~50% smaller than SQLite.Let me know how how that goes for you and feel free to ask more questions here.
JP
What is the best way to convert an existing Sqlite database to Realm? is there any tool or script for this?--And my other question is: Does Realm compresses data? Is there any comparison regarding size of same data in Sqlite and Realm?
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-users+unsubscribe@googlegroups.com.
#import <Foundation/Foundation.h>
#import <Realm/Realm.h>
#import "FMDatabase.h"
// Define your models
@interface Word : RLMObject
@property NSInteger _id;
@property NSString *word;
@property NSString *definition;
@end
@implementation Word
// No need for implementation
@end
RLM_ARRAY_TYPE(Word)
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray * array = [[NSMutableArray alloc] init];
RLMRealm *realm = [RLMRealm defaultRealm];
NSString * path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"db"];
FMDatabase * db = [FMDatabase databaseWithPath:path];
[db open];
NSLog(@"%@", db.databasePath);
NSString * query = [NSString stringWithFormat:@"select * from Words"];
FMResultSet *s = [db executeQuery:query];
while ([s next]) {
Word * word = [[Word alloc] init];
word._id = [s intForColumn:@"_id"];
word.word = [s stringForColumn:@"word"];
word.definition = [s stringForColumn:@"explanation"];
//NSLog(@"id: %ld", (long)word._id);
[array addObject:word];
}
NSLog(@"done1");
[realm beginWriteTransaction];
[realm addObjectsFromArray:array];
[realm commitWriteTransaction];
NSLog(@"done2");
RLMArray *words = [Word objectsWhere:@"_id = 203"];
NSLog(@"%@", words);
}
return 0;
}
now it works and converts the database correctly. but it is very very slow. It takes more than 15 minutes on my MacBook Pro to convert a 35 MB sqlite database with 50k row.
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-users/ca39d344-7ab2-4ace-b482-9ab34ef00fa2%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/2b88ae25-7998-41e1-93e0-0d5f743e0132%40googlegroups.com.
I want to use realm to store a huge dictionary of Persian language, so there is no write after some point, but I want database to be small and very fast. Can you estimate the time for this "compact" feature to be ready? and can you estimate the impact of this "compacting" on the size of database?
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/2b88ae25-7998-41e1-93e0-0d5f743e0132%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.