A simple SQLite Stack
[![CI Status](http://img.shields.io/travis/Khoa Pham/SQLiteStack.svg?style=flat)](https://travis-ci.org/Khoa Pham/SQLiteStack)
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Prefer protocol over inheritance via
FTGSQLiteSerializing
- Inspect model properties via
FTGModelHelper
- Convert model into SQLite statements via
FTGSQLiteHelper
- Create tables, execute statements via
FTGSQLiteStack
Model
#import <Foundation/Foundation.h>
#import "FTGSQLiteSerializing.h"
@interface FTGNote : NSObject <FTGSQLiteSerializing>
@property (nonatomic, copy) NSString *modelID;
@property (nonatomic, copy) NSString *content;
@property (nonatomic) NSTimeInterval timeInterval;
@end
@implementation FTGNote
+ (NSArray<NSString *> *)propertyKeys {
return @[@"modelID",
@"content",
@"timeInterval",
];
}
@end
DataManager
@implementation FTGDataManager
- (FTGNote *)createNoteWithContent:(NSString *)content {
FTGNote *note = [[FTGNote alloc] init];
note.modelID = [[NSUUID UUID] UUIDString];
note.content = content;
note.timeInterval = [[NSDate date] timeIntervalSince1970];
return note;
}
- (void)saveNotes:(NSArray<FTGNote *> *)notes {
FTGSQLiteHelper *helper = [FTGSQLiteHelper new];
NSArray<NSString *> *modifiedStatements = [notes map:^id(FTGNote *note) {
return [helper insertOrUpdateStatementForModel:note modelClass:[FTGNote class]];
}];
[self.stack executeStatements:modifiedStatements];
}
- (NSArray<FTGNote *> *)loadNotes {
return (id)[self.stack loadAllWithModelClass:[FTGNote class]];
}
@end
SQLiteStack is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SQLiteStack"
Khoa Pham, [email protected]
SQLiteStack is available under the MIT license. See the LICENSE file for more info.