-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RLMConfiguration #1584
Comments
Anything else? |
Should consider supporting:
|
Maybe also the classes that should be used for that schema? |
And let's align this with the Java cousin: realm/realm-java#929 |
The above are pretty much what I intended to add for Java as well, except from FileProtection which is not relevant on Java. I was also considering adding to other two initialisation methods:
Which covers some use cases we have seen pop up fairly often. |
How about https://developer.apple.com/library/ios/qa/qa1719/_index.html |
Below is the Objective-C API I've been sketching out, along with ////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <Realm/RLMRealm.h>
@protocol RLMConfigurator <NSObject>
@property (nonatomic, copy) NSString *path;
@property (nonatomic, copy) NSString *inMemoryIdentifier;
@property (nonatomic, copy) NSData *encryptionKey;
@property (nonatomic) BOOL readonly;
@property (nonatomic, copy) NSString *fileProtectionAttributes;
@property (nonatomic) NSUInteger schemaVersion;
@property (nonatomic, copy) RLMMigrationBlock migrationBlock;
@property (nonatomic) BOOL deleteBeforeOpening;
@property (nonatomic) BOOL deleteIfMigrationNeeded;
@end
@interface RLMConfiguration : NSObject<NSCopying>
+ (instancetype)defaultConfiguration;
+ (void)setDefaultConfiguration:(RLMConfiguration *)configuration;
+ (instancetype)configurationWithBlock:(void (^)(id <RLMConfigurator> configurator))block;
@property (nonatomic, copy, readonly) NSString *path;
@property (nonatomic, copy, readonly) NSString *inMemoryIdentifier;
@property (nonatomic, copy, readonly) NSData *encryptionKey;
@property (nonatomic, readonly) BOOL readonly;
@property (nonatomic, readonly) BOOL dynamic;
@property (nonatomic, copy, readonly) NSString *fileProtectionAttributes;
@property (nonatomic, copy) id customSchema;
@property (nonatomic, readonly) NSUInteger schemaVersion;
@property (nonatomic, copy, readonly) RLMMigrationBlock migrationBlock;
@property (nonatomic, readonly) BOOL deleteBeforeOpening;
@property (nonatomic, readonly) BOOL deleteIfMigrationNeeded;
@end |
I'd rather not have Same for Instead of file protection and potentially URL resource value properties, a way to get all realm files for a realm at a specified path might be more flexible. I can't think of a good way to separate As for the builder pattern, I think it lends itself well to having lots of options, especially if we continue to add some in the future. Good idea. |
After making some implementation progress, I'm not sure this feel like an improvement. In our own tests, what used to be one line to create a realm now requires 3-5 lines |
A few comments:
With regard to code length, I had the same thoughts as @segiddins about the brevity of unit tests. One just has to remember that unit tests are completely different beast than actually app code. In app code you would either set a default configuration or point to a global variabel holding the configuration, as you have very few Realm configurations there, but they are used repeatedly. Unit tests might have a lot of different configurations, and I found it a lot easier to either setup a default configuration in the unit test setup method or use a Factory class with almost the same API as the old constructors. |
what about cleaning of older schema? dropping not needed tables from other models? |
We just had a quick chat (@tgoyne @segiddins @bdash and I) and determined that to avoid multi-process race conditions, we should add a |
(This has been started in |
@segiddins @jpsim @bdash How do you plan to support schemaVersion/MigrationBlock? Currently on the Java side we have two separate methods for this:
It might make sense to combine these as having a version above 0 makes very little sense without a migration block at the same time. Something along the lines of
Counter to that is Our current behaviour is this:
|
Hey everyone, I've been lurking for the past few months waiting for a safe way to "delete if migration missing". Looks like the seg-config branch referenced above has gone stale. Are there still plans to add a Right now, I'm using a TryCatch block bridged from Obj-C (in Swift w/ objc Realm) with a NSFileManager.defaultManager().removeItemAtPath(
RLMRealm.defaultRealmPath(), error: nil
) This works most of the time, but I'm getting an occasional
Anyway, looking forward to hearing of any status updates! Cheers, |
we need a proper published guide on this |
Great job guys! I see these improvements got merged into master, when is it to be released? |
Encapsulate all global state/config used to configure Realms so that we don't need separate config methods for every parameter.
The text was updated successfully, but these errors were encountered: