-
Notifications
You must be signed in to change notification settings - Fork 18
Add support for custom paths and encrypted persistent Realms #4
base: master
Are you sure you want to change the base?
Conversation
| @override | ||
| void initState() { | ||
| super.initState(); | ||
| final encryptionKey = _secureRandom(64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the example generates a new encryption key every time the example is run. You will get a fatal error if you run the example a 2nd time because the keys will not match. It might be better to write the 1st encryption key to a file for demo purposes so someone can re-open the encrypted Realm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use constant in demo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. Will update.
| } else if (fileDirectory != null || fileName != null) { | ||
| if (fileDirectory != null) { | ||
| RealmConfiguration tmp = builder.build(); | ||
| File file = new File(tmp.getRealmDirectory(), fileDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if tmp.getRealmDirectory() is the most efficient way to get the default Realm directory. I would prefer to call builder.build() only once...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the case for custom directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From Realm:
The most common location to store writable Realm files is the “Documents” directory on iOS and the “Application Support” directory on macOS. Please respect Apple’s iOS Data Storage Guidelines, which recommend that if documents that can be regenerated by the app should be stored in the <Application_Home>/Library/Caches directory. If a custom URL is used to initialize a Realm, it must describe a location with write permissions.
For example, suppose you have an application where users have to log in to your web backend, and you want to support quickly switching between accounts. You could give each account its own Realm file that will be used as the default Realm by doing the following...
I think two use cases for custom directories:
- Your app needs to cache some non-user generated data and the cached data can be regenerated. The realm should technically be in the
.../Library/Cachesdirectory on iOS. Note that this PR does not support paths other than the standard documents directory on iOS or Android. If someone needs that flexibility in the future I'd suggest just adding acacheDirectoryproperty uses the appropriate base directory on iOS and Android. - My app allows multiple users on a single device which each user belonging to 1 or more projects. Data is sensitive and each user/project must have its own realm.
/user1/projectA/project.realm
/user1/projectA/additional_project_files...
/user1/projectB/project.realm
/user1/projectB/additional_project_files...
/user2/projectA/project.realm
etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about defining full path (including file name) in Dart code?
It simplifies plugin (native, duplicated) code in iOS and Android and resolves problems what if I want to use TMP, DOC,CACHE or another folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that. I started out that way but then switched to the current approach. My thought was that 95% of the time a developer would want to write to the DOC directory. Current approach made it so you don't need to use path_provider. Full path is more flexible though.
Side note, it may be awhile before I get around to making changes.
|
@swaffoja thanks for PR! |
|
Could you add integration tests to your cases? |
swaffoja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'll add tests.
fileDirectory and fileName merged into filePath
|
|
@mogol are you maintaining the repository yet? |
|
As of today, I do not use it and do not update. |
|
@mogol Do you find other one? Or, official team released? |
|
I haven't heard anything, I did some experiments and prototypes, after that I stopped using Realm as it doesn't fit my requirements |
PR for issue/proposal #3
local_realm_provider.dartcontains examples for various configuration options: