NewORM

ORM CoreAPI module

New implementation of the RHOM.

BETA VERSION – This API has not been officially released. It should not be used in a production environment.

Enabling the API

This API is part of the coreapi extension that is included automatically.

extensions: ["coreapi"]

JavaScript Usage

Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript.

If you are going to be using the JS ORM API, you’ll also need to include these lines in any files that will be using it:

<script type="text/javascript" charset="utf-8" src="/public/api/rhoapi-modules-ORM.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/api/rhoapi-modules-ORMHelper.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/api/rhoapi-modules-Ruby-RunTime.js"></script>

Ruby Usage

For Ruby access to the RHOM database please see the Rhom Ruby API guide.

Methods

addModel
( Anoynomous Function methods)

Creates an ORM model reference.

Parameters

  • Anoynomous Function methods :

    • enable("value") : STRING Optional

      Enables Model Properties.

      Possible Values :

      sync

      If set then model is set for RhoConnect Sync.

      propertyBag

      (Default) Model will be of type propertyBag.

      fixedSchema

      Model will be of type fixedSchema.

      full_update

      Instruct ORM to send all attributes to RhoConnect when an object is updated. By Default it is disabled.

      pass_through

      RhoConnect provides a simple way to keep data out of redis. If you have sensitive data that you do not want saved in redis, add the pass_through option in settings/settings.yml for each source.

    • setModelproperty("name","type","option") : STRING,STRING,STRING Optional

      Used to create properties on your model.

      • name : STRING

        The name of the property.

      • type : STRING

        The type of property. Possible values are: String, Float, integer, Varchar, Blob. String is default.

      • option : STRING Optional Default: Null

        Possible Values :

        overwrite

        Overwrite client copy of blob with the new copy from server. This is useful when RhoConnect modifies images sent from Rhodes, for example zooming or cropping.

    • set("property","value") : STRING,VALUE Optional

      Sets the Behavior of this model. Possible ‘property’ options and the corresponding ‘value’s are passed as the parameter.

      • partition : STRING

        The partition to use for this model. Partitions can be used to segment the data and keep non-synched data separate from synched models.

        Possible Values :

        local

        This partition is used automatically if the model is not a sync model.

        user

        This partition is used automatically if the model is a sync model.

        app

        This partition is used to store the application related information.

      • sync_type : STRING

        Sets the type of sync it will be.

        Possible Values :

        none

        If data model is not a sync model.

        incremental

        Used when the data model is a sync model. Just syncs changes.

        bulk_only

        If the model is used only for bulk sync.

      • sync_priority : INTEGER

        This number determines the order in which the models are processed and synchronised. Priority starts from lower value 1. Lower the number, higher is the priority. Default value is 1000.

      • freezed : BOOLEAN

        To make the model Freezed.

      • schema_version : FLOAT

        This is used for data migration of the application.

Synchronous Return:

  • Model

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.addModel( Anoynomous Function methods)
databaseClientReset
(BOOLEAN resetLocalModels)

Resets client info and sync models (optionally, local models as well)

Parameters

  • resetLocalModels : BOOLEAN Default: true

    Whether or not to reset Local Models.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseClientReset(BOOLEAN resetLocalModels)
    • Ruby: Rho::NewORM.databaseClientReset(BOOLEAN resetLocalModels)
databaseFullReset
(BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)

Resets selected models, client info and local models.

Parameters

  • resetClientInfo : BOOLEAN Optional Default: false

    Whether or not to reset Client Info.

  • resetLocalModels : BOOLEAN Optional Default: true

    Whether or not to reset Local Models.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseFullReset(BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)
    • Ruby: Rho::NewORM.databaseFullReset(BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)
databaseFullResetAndLogout
()

Resets sync models, client info and local models and does the user logout.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseFullResetAndLogout()
    • Ruby: Rho::NewORM.databaseFullResetAndLogout()
databaseFullResetEx
(ARRAY models, BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)

Resets selected models, client info and local models.

Parameters

  • models : ARRAY

    List of models to reset.

  • resetClientInfo : BOOLEAN

    Whether or not to reset Client Info.

  • resetLocalModels : BOOLEAN

    Whether or not to reset Local Models.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseFullResetEx(ARRAY models, BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)
    • Ruby: Rho::NewORM.databaseFullResetEx(ARRAY models, BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)
databaseFullclientResetAndLogout
()

Resets sync models, client info and local models and does the user logout.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseFullclientResetAndLogout()
    • Ruby: Rho::NewORM.databaseFullclientResetAndLogout()
databaseLocalReset
()

Resets local database.

Synchronous Return:

  • Void

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.databaseLocalReset()
    • Ruby: Rho::NewORM.databaseLocalReset()
getClientId
()

Returns current Client Id.

Synchronous Return:

  • STRING

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.getClientId()
    • Ruby: Rho::NewORM.getClientId()
haveLocalChanges
()

Returns TRUE whenever there are any local (non-synced) changes.

Synchronous Return:

  • BOOLEAN

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.haveLocalChanges()
    • Ruby: Rho::NewORM.haveLocalChanges()
useNewOrm
()

Returns TRUE if NewORM is enabled in rhoconfig.txt.

Synchronous Return:

  • BOOLEAN

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORM.useNewOrm()
    • Ruby: Rho::NewORM.useNewOrm()

Examples

addModel

This example describes creating model and adding model object.

var Customer = function(model){
  model.enable("sync");
  model.setModelProperty("name","string","");
  model.setModelProperty("brand","string","");
  model.setModelProperty("price","float","");
  model.set("partition","user");
  model.set("schema_version",'1.1');
};
var custobj = Rho.ORM.addModel("Customer", Customer);
// create model object and save it to database
var customer = custobj.createObject({
  brand: "Apple",
  name: "iPhone5",
  price: 199.99});

                            
databaseFullResetEx

This example clears the local model’s passed through the array only. It doesn’t reset the client_info table.

var ary = ['Product','Product2'];               
Rho.ORM.databaseFullResetEx(ary, false, true);
                            
ary = ['Product','Product2']                
Rho.ORM.databaseFullResetEx(ary, false, true)