Database options for version migration

This commit is contained in:
relikd
2019-08-09 21:07:54 +02:00
parent dff1594926
commit c717487b0e
10 changed files with 139 additions and 11 deletions

View File

@@ -64,13 +64,35 @@
}
#pragma mark - Options
/// @return Value for option with @c key or @c nil.
+ (nullable NSString*)optionForKey:(NSString*)key {
return [[[Options fetchRequest] where:@"key = %@", key] fetchFirst:[self getMainContext]].value;
}
/// Init new option with given @c key
+ (void)setOption:(NSString*)key value:(NSString*)value {
NSManagedObjectContext *moc = [self getMainContext];
Options *opt = [[[Options fetchRequest] where:@"key = %@", key] fetchFirst:moc];
if (!opt) {
opt = [[Options alloc] initWithEntity:Options.entity insertIntoManagedObjectContext:moc];
opt.key = key;
}
opt.value = value;
[self saveContext:moc andParent:YES];
[moc reset];
}
#pragma mark - Feed Update
/// @return @c NSDate of next (earliest) feed update. May be @c nil.
+ (NSDate*)nextScheduledUpdate {
NSFetchRequest *fr = [FeedMeta fetchRequest];
[fr addFunctionExpression:@"min:" onKeyPath:@"scheduled" name:@"minDate" type:NSDateAttributeType];
return [fr fetchAllRows: [self getMainContext]].firstObject[@"minDate"];
return [fr fetchFirstDict: [self getMainContext]][@"minDate"];
}
/**
@@ -140,7 +162,7 @@
/// @return URL of @c Feed item where @c Feed.indexPath @c = @c path.
+ (NSString*)urlForFeedWithIndexPath:(nonnull NSString*)path {
return [[[[Feed fetchRequest] where:@"indexPath = %@", path] select:@[@"link"]] fetchFirst: [self getMainContext]][@"link"];
return [[[[Feed fetchRequest] where:@"indexPath = %@", path] select:@[@"link"]] fetchFirstDict: [self getMainContext]][@"link"];
}
/// @return Unsorted list of object IDs where @c Feed.indexPath begins with @c path @c + @c "."