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

Checking type with DynamicRealm's RealmSchema #1883

Closed
NikoYuwono opened this Issue Dec 4, 2015 · 11 comments

Comments

Projects
None yet
4 participants
@NikoYuwono

Hello,

Previously I'm using Table to check the type of the column now I'm trying to migrate to DynamicRealm because direct access to Table will be deprecated soon.

I think I can get the name of the field with using

RealmObjectSchema realmObjectSchema = dynamicRealm.getSchema().get(selectedTableName);
Set<String> fieldNames = realmObjectSchema.getFieldNames();

But how to get the field types?

Thank you!

@beeender

This comment has been minimized.

Show comment
Hide comment
@beeender

beeender Dec 4, 2015

Contributor

Uh... I think that API is missing and we should add it ...
@cmelchior

Contributor

beeender commented Dec 4, 2015

Uh... I think that API is missing and we should add it ...
@cmelchior

@NikoYuwono

This comment has been minimized.

Show comment
Hide comment
@NikoYuwono

NikoYuwono Dec 4, 2015

Thank you! will wait for the API implementation before migrating to DynamicRealm then!

Thank you! will wait for the API implementation before migrating to DynamicRealm then!

@cmelchior

This comment has been minimized.

Show comment
Hide comment
@cmelchior

cmelchior Dec 4, 2015

Contributor

Hi @NikoYuwono
Can you elaborate on your use case when using RealmObjectSchema? Because ideally you shouldn't need to query the schema for the type. It is information you should already know.

I believe we left it out intentionally in RealmObjectSchema because we are only able to expose the underlying Realm data type and not the type used in your Java RealmObject class, e.g short, int and long would all be of the type RealmFieldType.INTEGER, and there was concern that might be confusing.

Note that the information is available in DynamicRealmObject where you can do obj.getFieldType("fieldName").

I am not totally against adding it to RealmObjectSchema, but knowing your use case will help a lot.

Contributor

cmelchior commented Dec 4, 2015

Hi @NikoYuwono
Can you elaborate on your use case when using RealmObjectSchema? Because ideally you shouldn't need to query the schema for the type. It is information you should already know.

I believe we left it out intentionally in RealmObjectSchema because we are only able to expose the underlying Realm data type and not the type used in your Java RealmObject class, e.g short, int and long would all be of the type RealmFieldType.INTEGER, and there was concern that might be confusing.

Note that the information is available in DynamicRealmObject where you can do obj.getFieldType("fieldName").

I am not totally against adding it to RealmObjectSchema, but knowing your use case will help a lot.

@beeender

This comment has been minimized.

Show comment
Hide comment
@beeender

beeender Dec 4, 2015

Contributor

One use case is for a phone-side Realm browser. Showing data without knowing the schema during the compiling time.

Contributor

beeender commented Dec 4, 2015

One use case is for a phone-side Realm browser. Showing data without knowing the schema during the compiling time.

@cmelchior

This comment has been minimized.

Show comment
Hide comment
@cmelchior

cmelchior Dec 4, 2015

Contributor

But the schema is only meta-data? To show any information in a browser you would use DynamicRealmObject?

Contributor

cmelchior commented Dec 4, 2015

But the schema is only meta-data? To show any information in a browser you would use DynamicRealmObject?

@beeender

This comment has been minimized.

Show comment
Hide comment
@beeender

beeender Dec 4, 2015

Contributor

You need to know meta data before deciding to call DynamicObject.getInt() or DynamicObject.getString(). Right?

Contributor

beeender commented Dec 4, 2015

You need to know meta data before deciding to call DynamicObject.getInt() or DynamicObject.getString(). Right?

@NikoYuwono

This comment has been minimized.

Show comment
Hide comment
@NikoYuwono

NikoYuwono Dec 4, 2015

Hi @cmelchior currently I'm trying to create a phone-side Realm browser like @beeender said. I want to use Reflection as little as possible that's why I'm trying to access the Field type so I can get the data from DynamicRealmObject.

From what I understand I can only get the data with

String name = person.getString("name");

but if I don't know what's the type of the field how can I determine which function should I call?
Before I'm using switch-case on ColumnType but looks like it become deprecated in 0.86.0

Hi @cmelchior currently I'm trying to create a phone-side Realm browser like @beeender said. I want to use Reflection as little as possible that's why I'm trying to access the Field type so I can get the data from DynamicRealmObject.

From what I understand I can only get the data with

String name = person.getString("name");

but if I don't know what's the type of the field how can I determine which function should I call?
Before I'm using switch-case on ColumnType but looks like it become deprecated in 0.86.0

@cmelchior

This comment has been minimized.

Show comment
Hide comment
@cmelchior

cmelchior Dec 4, 2015

Contributor

You can also do person.get("name"), which would probably be enough for all simple types, but I agree that if you want to make a browser that shows RealmLists and RealmObject references in another way it can be a bit problematic.

I'll add it.

Contributor

cmelchior commented Dec 4, 2015

You can also do person.get("name"), which would probably be enough for all simple types, but I agree that if you want to make a browser that shows RealmLists and RealmObject references in another way it can be a bit problematic.

I'll add it.

@NikoYuwono

This comment has been minimized.

Show comment
Hide comment
@NikoYuwono

NikoYuwono Dec 4, 2015

Yes that's what I thought with doing the type checking by myself. Will try that one too though while waiting for the new release.
Thanks @cmelchior and @beeender will wait for the next release!

Yes that's what I thought with doing the type checking by myself. Will try that one too though while waiting for the new release.
Thanks @cmelchior and @beeender will wait for the next release!

@saket

This comment has been minimized.

Show comment
Hide comment
@saket

saket Dec 4, 2015

@NikoYuwono Really need a phone-side Realm browser :)

saket commented Dec 4, 2015

@NikoYuwono Really need a phone-side Realm browser :)

@NikoYuwono

This comment has been minimized.

Show comment
Hide comment
@NikoYuwono

NikoYuwono Dec 4, 2015

@Saketme will try to release initial version next Tuesday!

@Saketme will try to release initial version next Tuesday!

@cmelchior cmelchior closed this in #1888 Dec 4, 2015

@cmelchior cmelchior removed the P1 label Dec 4, 2015

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