-
Notifications
You must be signed in to change notification settings - Fork 87
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
Support Map data types. #685
Comments
We do not currently support
In particular realm maps are not directly suitable for storing json. |
whats is GA? |
Is this already works? |
No, this didn't make it into the 1.0 release, but the team is looking to add support for maps in the near future. |
do they have a deadline ? |
We have a policy not to communicate timelines publicly. If you're using sync/Atlas App Services and this feature is critical for your application, please reach out to your account executive or support and they should be able to give you more concrete answers. |
Any update on Maps being supported? |
Hi, this is high priority on our list for the upcoming features. |
Hey @blagoev thanks for the update, is there an ETA ? |
@plotic |
What is the suggested workaround? Should I store keys and values in two different lists? |
@MICKEY88661 You could do something like this: import 'package:realm_dart/realm.dart';
part 'fake_map.g.dart';
@RealmModel()
class _MapEntry {
@PrimaryKey()
@MapTo('_id')
late int id; // cannot use key directly
late String key;
late RealmValue value;
}
@RealmModel()
class _Stuff {
@PrimaryKey()
@MapTo('_id')
late ObjectId id;
late Set<_MapEntry> fakeMap;
}
extension on RealmSet<MapEntry> {
T? mapLookup<T>(String key) {
return query('key == \$0', [key]).singleOrNull?.value.as<T>();
}
void mapInsert<T>(Object parentId, String key, T value) {
final entry = MapEntry(
Object.hash(parentId, key),
key,
value: RealmValue.from(value),
);
realm.add(entry, update: true);
add(entry);
}
}
void main(List<String> arguments) {
final realm = Realm(Configuration.inMemory([Stuff.schema, MapEntry.schema]));
final stuff = realm.write(() {
final stuff = Stuff(ObjectId());
realm.add(stuff);
stuff.fakeMap
..mapInsert(stuff.id, 'a', 'value')
..mapInsert(stuff.id, 'b', 1);
final anotherStuff = Stuff(ObjectId());
realm.add(anotherStuff);
anotherStuff.fakeMap
..mapInsert(anotherStuff.id, 'a', 'not what you want')
..mapInsert(anotherStuff.id, 'b', 666);
return stuff;
});
assert(stuff.fakeMap.mapLookup<String>('a') == 'value');
assert(stuff.fakeMap.mapLookup<int>('b') == 1);
realm.all<MapEntry>().forEach((entry) {
print('${entry.id} ${entry.key} => ${entry.value}');
});
Realm.shutdown();
} If you really need it, but it obviously impacts your schema. |
Hi @nirinchev . |
Hey guys. Do we have any updates on this? |
Not yet, unfortunately. |
Has the support for Nested Maps been provided ? For eg : I wanted to store the following data as RealmMap:
My parentRealm Objects is as ::
I couldn't figure out how to store , a Map Datatype with in a value of a key in the map . ( I think i can tackle this issue embedded object inside a map instead of nested map , but that is not my preference ) So is it possible to implement nested maps ? (If not , are there any plans to implement that ). Note On the RealmValue class , I saw RealmValue.fromString() ..fromDateTime() and all . |
This will land with #1469 (soon) |
This is not supported today, but we're working on it. You can follow this PR: #1469, which adds the ability to store collections inside RealmValue. |
@nirinchev thanks . Is there any ETA ? |
Not yet - it's fairly close to completion for the local database, but if you're using Sync, you'll need to wait a bit longer for server side support. |
@nirinchev Hii, any updates on this? |
This has been implemented for the local database and we're close to being done for sync. We expect to release it in the next couple of weeks. |
thanks |
@nirinchev Seems like, sync for maps has arrived on the stable 2.0. Still Couldnt figure out how to handle sync for nested Maps . For Something like :
|
We're rolling out sync support, so we haven't enabled it for all customers/apps yet. If you want to test it out asap, you can open a support ticket and ask the team to enable it for your app. |
Can I use Map data type for realm model in flutter?
Like this one,
final Map<String, dynamic> properties;
The text was updated successfully, but these errors were encountered: