Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
NyaruDB
@starfruits_j (Little Gleam)
 Azione
Azione
Web
Swift?!
Nator
© 2014 Azione Co.,Ltd. All Right Reserved.
DB ( )
SQL
DB
DB
typo
[NSString stringWithFormat:]
INDEX
SQLite(FMDB)
3GS
FMDatabaseQueue
REINDEX
ALTER TABLE mails ADD COLUMN answered INTEGER DEFAULT ....
...
Sparrow
OpenSource
OSS !=
TokyoCabinet
NoSQL - 
SQL
..
API ( )
NoJSON, NoARC NoIB
main.m
int main(int argc, char *argv[])
{
@autoreleasepool {
if ([AppSettings isOS8OrGreater]) {
return UIApplicationMain(...
DB SQL
github
NyaruDB
https://github.com/kelp404/NyaruDB
( )SAN ( )
W
2013 4 7 1:05
MIT License
NyaruDB is a simple NoSQL database in
Ob...
DB
SQL
NyaruDB SQL
CocoaPods
SQL
_documentFilePath
_indexFilePath
NSFileHandle seek
Table key
select
(asyncFetch)
AsyncDisplayKit
10
SQL
KeyValueStore
NSDictionary NSDictionary
- (NSString *)name {
return _dic[@"name"];
}
- (void)setName:(NSString *)name ...
NyaruCollection *col = [[NyaruDB instance] collection:@"articles"];
[col createIndex:@"user_id"];
[col put:@{
@"user_id" :...
JSON
- (instansetype)initWithDictionary:(NSDictionary *)dictionary {
if ((self = [super init])) {
_dic = dictionary;
}
ret...
SELECT
NSArray *results = [[col all] fetch];
WHERE
NSDictionary *result = [[col where:@"user_id" equal:identifier] fetchFirst];
AND
where: => NyaruQuery
[[self.col where:@"user_id" less:100]
and:@"user_id" greater:10]];
NyaruQuery
- (NyaruQuery *)and:(NSString *)indexName equal:(id)value;
- (NyaruQuery *)and:(NSString *)indexName notEqual:(...
 : JSON
NSNull nil
limit length of field name is 255
limit of documents is 4,294,967,295
limit of document file size is 4G
key is unique and ...
http://realm.io/
Realm is a mobile database: a replacement for
SQLite & Core Data Realm can save you
thousands of lines of...
CocoaPods
SQL
RLMObject
Table Class
@interface User : RLMObject
@property (nonatomic, copy) NSString *identifier;
@propert...
SQL
@interface User : RLMObject
@property (nonatomic, copy) NSString *identifier;
@property (nonatomic, copy) NSString *name;
...
INSERT
[[RLMRealm defaultRealm] transactionWithBlock:^{
[[RLMRealm defaultRealm] addObject:user];
[[RLMRealm defaultRealm]...
SELECT
RLMResults *users = [User allObjects];
RLMResults
NSArray (for in )
@interface RLMResults : NSObject<RLMCollection, NSFastEnumeration>
...
- (id)objectAtIndex:(N...
WHERE
User *user = [[User objectsWhere:@"identifier = %@", identifier] firstObject];
NSPredicate NSPredicate
AND
objectsWhere: => RLMResults
[[User objectsWhere:@"age < %@", @(20)]
objectsWhere:@"age > %@", @(2)]];
RLMResults
@interface Picture : RLMObject
@property (nonatomic, assign) BOOL isDeleted;
...
+ (RLMResults *)pictures {
ret...
delete
[[RLMRealm defaultRealm] transactionWithBlock:^{
[[RLMRealm defaultRealm] deleteObjects:[Picture myPictures]];
}];
...
Migration
[RLMRealm setSchemaVersion:9
withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) {
if (ol...
[RLMRealm defaultRealm]
DB
DB
notification
_token = [[RLMRealm defaultRealm]
addNotificationBlock:^(NSString *notification, RLMRealm *realm) {
// code
}...
AppDelegate migration
ViewController initWithCoder:
NSURL
Java
getter
https://github.com/jstarfruits/BenchDB
normal single main (10,000)
FMDB 00.24 49.194 00.617
NyaruDB 29.02 17.890 59.186
Re...
SQLite
Realm NyaruDB SQL
NyaruDB -
Realm -
FMDB -
Realm
Azione
azione.co.jp
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
What to Upload to SlideShare
Next
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

Share

NyaruDBにゃるものを使ってみた話 (+Realm比較)

Download to read offline

NyaruDBというNoSQLライブラリを使ってみたので、その話とRealmについても少し。

Related Books

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

NyaruDBにゃるものを使ってみた話 (+Realm比較)

  1. 1. NyaruDB
  2. 2. @starfruits_j (Little Gleam)
  3. 3.  Azione Azione Web
  4. 4. Swift?!
  5. 5. Nator © 2014 Azione Co.,Ltd. All Right Reserved.
  6. 6. DB ( ) SQL
  7. 7. DB
  8. 8. DB typo [NSString stringWithFormat:] INDEX
  9. 9. SQLite(FMDB) 3GS
  10. 10. FMDatabaseQueue
  11. 11. REINDEX
  12. 12. ALTER TABLE mails ADD COLUMN answered INTEGER DEFAULT ....
  13. 13. ...
  14. 14. Sparrow OpenSource
  15. 15. OSS != TokyoCabinet
  16. 16. NoSQL -  SQL ..
  17. 17. API ( ) NoJSON, NoARC NoIB
  18. 18. main.m int main(int argc, char *argv[]) { @autoreleasepool { if ([AppSettings isOS8OrGreater]) { return UIApplicationMain(argc, argv, nil, NSStringFromClass([MB2AppDelegate class])); } return UIApplicationMain(argc, argv, nil, NSStringFromClass([ScreenFactory class])); } }
  19. 19. DB SQL github
  20. 20. NyaruDB https://github.com/kelp404/NyaruDB ( )SAN ( ) W 2013 4 7 1:05 MIT License NyaruDB is a simple NoSQL database in Objective-C. It could be run on iOS and OS X. It is a key-valu pair NoSQL database. You could search data by fields of the document.
  21. 21. DB SQL
  22. 22. NyaruDB SQL
  23. 23. CocoaPods SQL
  24. 24. _documentFilePath _indexFilePath NSFileHandle seek
  25. 25. Table key select (asyncFetch) AsyncDisplayKit
  26. 26. 10
  27. 27. SQL KeyValueStore NSDictionary NSDictionary - (NSString *)name { return _dic[@"name"]; } - (void)setName:(NSString *)name { _dic[@"name"] = name; } JSON OK
  28. 28. NyaruCollection *col = [[NyaruDB instance] collection:@"articles"]; [col createIndex:@"user_id"]; [col put:@{ @"user_id" : @1 @"name" : @"Cocoa", @"age" : @"test", }]; instance singleton collection close instance
  29. 29. JSON - (instansetype)initWithDictionary:(NSDictionary *)dictionary { if ((self = [super init])) { _dic = dictionary; } return self; } - (void)save { [self.col put:_dic]; } "key" primarykey key update
  30. 30. SELECT NSArray *results = [[col all] fetch];
  31. 31. WHERE NSDictionary *result = [[col where:@"user_id" equal:identifier] fetchFirst];
  32. 32. AND where: => NyaruQuery [[self.col where:@"user_id" less:100] and:@"user_id" greater:10]];
  33. 33. NyaruQuery - (NyaruQuery *)and:(NSString *)indexName equal:(id)value; - (NyaruQuery *)and:(NSString *)indexName notEqual:(id)value; - (NyaruQuery *)and:(NSString *)indexName less:(id)value; - (NyaruQuery *)and:(NSString *)indexName lessEqual:(id)value; - (NyaruQuery *)and:(NSString *)indexName greater:(id)value; - (NyaruQuery *)and:(NSString *)indexName greaterEqual:(id)value; - (NyaruQuery *)and:(NSString *)indexName like:(NSString *)value; - (NyaruQuery *)or:(NSString *)indexName equal:(id)value; - (NyaruQuery *)orderBy:(NSString *)indexName; - (NyaruQuery *)orderByDESC:(NSString *)indexName;
  34. 34.  : JSON NSNull nil
  35. 35. limit length of field name is 255 limit of documents is 4,294,967,295 limit of document file size is 4G key is unique and it is NSString key only provides equal search key is case sensitive index is case insensitive a field of the document should be same data type which is index sort query allow only one
  36. 36. http://realm.io/ Realm is a mobile database: a replacement for SQLite & Core Data Realm can save you thousands of lines of code & weeks of work, and lets you craft amazing new user experiences.
  37. 37. CocoaPods SQL RLMObject Table Class @interface User : RLMObject @property (nonatomic, copy) NSString *identifier; @property (nonatomic, copy) NSString *name; @end
  38. 38. SQL
  39. 39. @interface User : RLMObject @property (nonatomic, copy) NSString *identifier; @property (nonatomic, copy) NSString *name; @end + (NSString *)primaryKey { return @"identifier"; }
  40. 40. INSERT [[RLMRealm defaultRealm] transactionWithBlock:^{ [[RLMRealm defaultRealm] addObject:user]; [[RLMRealm defaultRealm] addOrUpdateObject:user]; }];
  41. 41. SELECT RLMResults *users = [User allObjects];
  42. 42. RLMResults NSArray (for in ) @interface RLMResults : NSObject<RLMCollection, NSFastEnumeration> ... - (id)objectAtIndex:(NSUInteger)index; - (id)firstObject; - (id)lastObject; ... @end
  43. 43. WHERE User *user = [[User objectsWhere:@"identifier = %@", identifier] firstObject]; NSPredicate NSPredicate
  44. 44. AND objectsWhere: => RLMResults [[User objectsWhere:@"age < %@", @(20)] objectsWhere:@"age > %@", @(2)]];
  45. 45. RLMResults @interface Picture : RLMObject @property (nonatomic, assign) BOOL isDeleted; ... + (RLMResults *)pictures { return [self objectsWhere:@"isDeleted = 0"]; } + (RLMResults *)deletedPictures { return [self objectsWhere:@"isDeleted = 1"]; } + (RLMResults *)myPictures { RLMResults *res = [self pictures]; res = [res objectsWhere:@"user_id", [Account identifier]]; res = [res sortedResultsUsingProperty:@"created" ascending:NO]; return res; }
  46. 46. delete [[RLMRealm defaultRealm] transactionWithBlock:^{ [[RLMRealm defaultRealm] deleteObjects:[Picture myPictures]]; }];
  47. 47. ...
  48. 48. Migration [RLMRealm setSchemaVersion:9 withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) { if (oldSchemaVersion < 8) { [migration enumerateObjects:NSStringFromClass([Pictures class]) block:^(RLMObject *oldObject, RLMObject *newObject) { newObject[@"updated"] = oldObject[@"created"]; }]; } }]; schemaVersion
  49. 49. [RLMRealm defaultRealm] DB DB
  50. 50. notification _token = [[RLMRealm defaultRealm] addNotificationBlock:^(NSString *notification, RLMRealm *realm) { // code }]; NSMapTable token
  51. 51. AppDelegate migration ViewController initWithCoder: NSURL Java getter
  52. 52. https://github.com/jstarfruits/BenchDB normal single main (10,000) FMDB 00.24 49.194 00.617 NyaruDB 29.02 17.890 59.186 Realm 04.18 28.744 00.385
  53. 53. SQLite Realm NyaruDB SQL NyaruDB - Realm - FMDB -
  54. 54. Realm
  55. 55. Azione azione.co.jp

NyaruDBというNoSQLライブラリを使ってみたので、その話とRealmについても少し。

Views

Total views

725

On Slideshare

0

From embeds

0

Number of embeds

36

Actions

Downloads

3

Shares

0

Comments

0

Likes

0

×