realm-js
realm-js copied to clipboard
Create Schema During Run Time Javascript
Goals
Create Schema (Tables) on Realm Database during run time
Expected Results
Realm object to provide an api similar to create and other api's to add a new schema
Actual Results
No such Api available to overcome the above scenario
Steps to Reproduce
Code Sample
Version of Realm and Tooling
- Realm JS SDK Version: ?
- Node or React Native: ?
- Client OS & Version: ?
- Which debugger for React Native: ?/None
@KartikSubramaniam True, Realm JS does not provide such an API. I'll label this issue as a feature request but I can't give you an estimate when we will implement it.
Hi @kneth,
Is there any workaround for the same? Is it a unique requirement? Any idea how other folks are achieving this feature?
Thanks Pranav
Realm Java can open a Realm in a dynamic mode. It give you full flexibility but the cost is high as introspection is expensive.
You can manipulate the schema but is can be a bit cumbersome. The documentation has this example.
Thanks @kneth for the quick response. I will try the provided reference
Thanks Pranav
Hi @kneth,
Is it advisable to use realm open, n number of times in the application and if we use it apart from maintaining the realm object is there any other drawback for this used case.
Thanks Kartik
The Realm instance is cached so opening it multiple times doesn't hurt you. If the schema or schema version is changed, you'll get a brand new instance.
It is advisable to remember to close instances.
Hi @kneth
I was using Realm 2.1.1 and I'am planning to use the latest version of realm which is 2.4.0. But I'am facing a issue in it.
Earlier I was able to create multiple realm instance and was able to create schema dynamically in run time but after migrating to realm 2.4.0 I'am not able to create multiple realm references which is causing a deadlock to my architecture.
PFA screenshot for the same.
Please provide your advice on the same

Thanks Kartik Subramaniam
Hi @kneth ,
Can you Please share your thoughts for the above issue that I'am facing.
Thanks Kartik
@KartikSubramaniam When you open Realms with different schemas, be sure to use different file names. You screenshot indicates that you are using the default name.
@kneth Thanks for your help, In the earlier version that I was using it was allowing me to save all schemas under the same file. As suggested I'll make the new changes and create new files for all schemas.
Can you share your thoughts whether this approach will be beneficial or not in terms of performance because I might land up into situations accessing multiple files at the same time so will there be a performance issue for the same.
Thanks Kartik
@KartikSubramaniam I think I am misreading your comment - sorry. Of course you can have multiple schemas in one file. And you can open multiple instances of the same Realm. You will see this error message if the schema is set in the configuration and schema_version is different from previously created instances. Did you set schema to an empty list? If so, try to remove that part.
@kneth @KartikSubramaniam Was this issue resolved? @kneth in that case please relabel.
@bmunkholm The label is correct for the original issue but it seems to attract other (related) questions.
Ok. Let's encourage new issues instead in the future then :-)
Hi @kneth Is it possible to create tables (schema) dynamically now ?
@akhilvasudev-kiwi Realm Studio is experimenting with using an internal (undocumented) API to make changes to the schema without having to close and reopen the Realm: https://github.com/realm/realm-studio/blob/kh/realm-browser-with-context/src/ui/RealmBrowser/index.tsx#L495-L509 Please note: This API is experimental and if it's changed or completely removed it won't be a breaking change or be mentioned in the changelog. Use at your own risk :)