Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.

Conversation

@swaffoja
Copy link

PR for issue/proposal #3

local_realm_provider.dart contains examples for various configuration options:

  • In-memory Realm
  • Default persistent Realm
  • Custom file name in default directory
  • Subdirectory under default directory
  • Custom file name and subdirectory
  • Encrypted Realm

@override
void initState() {
super.initState();
final encryptionKey = _secureRandom(64);
Copy link
Author

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.

Copy link
Owner

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?

Copy link
Author

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);
Copy link
Author

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...

Copy link
Owner

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?

Copy link
Author

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:

  1. 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/Caches directory 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 a cacheDirectory property uses the appropriate base directory on iOS and Android.
  2. 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...

Copy link
Owner

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.

Copy link
Author

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.

@mogol
Copy link
Owner

mogol commented Nov 7, 2019

@swaffoja thanks for PR!
I will check it soon, somehow I haven't seen notifications

@mogol
Copy link
Owner

mogol commented Nov 8, 2019

Could you add integration tests to your cases?
It should help to keep the plugin workable, e.g. when Realm version is updated.

Copy link
Author

@swaffoja swaffoja left a 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.

@swaffoja
Copy link
Author

  • Reverted local_realm_provider.dart to original
  • Added encrypted_realm_provider.dart to illustrate encryption and full file path usage
  • Added integration test for encrypted realm provider
  • Added unit test for encryption

@shinriyo
Copy link

@mogol are you maintaining the repository yet?

@mogol
Copy link
Owner

mogol commented May 24, 2020

As of today, I do not use it and do not update.

@shinriyo
Copy link

@mogol Do you find other one? Or, official team released?

@mogol
Copy link
Owner

mogol commented May 24, 2020

I haven't heard anything, I did some experiments and prototypes, after that I stopped using Realm as it doesn't fit my requirements

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants