realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Create Schema During Run Time Javascript

Open KartikSubramaniam opened this issue 7 years ago • 16 comments

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 avatar Jan 10 '18 10:01 KartikSubramaniam

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

kneth avatar Jan 11 '18 09:01 kneth

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

prscX avatar Jan 11 '18 09:01 prscX

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.

kneth avatar Jan 11 '18 10:01 kneth

Thanks @kneth for the quick response. I will try the provided reference

Thanks Pranav

prscX avatar Jan 11 '18 11:01 prscX

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

KartikSubramaniam avatar Jan 12 '18 12:01 KartikSubramaniam

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.

kneth avatar Jan 15 '18 09:01 kneth

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

realmerror

Thanks Kartik Subramaniam

KartikSubramaniam avatar May 08 '18 13:05 KartikSubramaniam

Hi @kneth ,

Can you Please share your thoughts for the above issue that I'am facing.

Thanks Kartik

KartikSubramaniam avatar May 14 '18 06:05 KartikSubramaniam

@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 avatar May 14 '18 08:05 kneth

@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 avatar May 14 '18 09:05 KartikSubramaniam

@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 avatar May 15 '18 08:05 kneth

@kneth @KartikSubramaniam Was this issue resolved? @kneth in that case please relabel.

bmunkholm avatar Jun 14 '18 09:06 bmunkholm

@bmunkholm The label is correct for the original issue but it seems to attract other (related) questions.

kneth avatar Jul 12 '18 14:07 kneth

Ok. Let's encourage new issues instead in the future then :-)

bmunkholm avatar Jul 12 '18 15:07 bmunkholm

Hi @kneth Is it possible to create tables (schema) dynamically now ?

ghost avatar Jun 01 '20 14:06 ghost

@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 :)

kraenhansen avatar Jun 02 '20 08:06 kraenhansen