This JavaScript API class allows you to interact with the local RHOM database and programatically add models or get references to models.
This API is part of the coreapi
extension that is included automatically.
extensions: ["coreapi"]
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript
For Ruby access to the RHOM database please see the Rhom Ruby API guide.
Creates an ORM model reference.
Parameters
The name of your model.
Enables Model Properties.
Possible Values :
Used to create properties on your model.
The name of the property
The type of property value: String, Float, integer, Varchar, Blob - String is default
Add an index to your fixedSchema model.
The name of the index
Array of model column names to use in index, Ex: ['name','qty']
Add an index to your fixedSchema model.
The name of the index
Array of model column names to use in index, Ex: ['name','qty']
Add belongs_to association to another defined model, for sync models. Comma separted String for more than one model.
Set Behavior of this model. Possible `property` options and corresponding values:
The partition to use for this model. Partitions can be used to segment the data and keep non-synched data seperate from synched models. Possible `values`
Possible Values :
Sets the type of sync it will be.
Possible Values :
Determines how frequently to check for changes. In seconds. Default is 1000.
Synchronous Return:
Method Access:
Rho.ORM.addModel( Anoynomous Function methods)
Deletes all records from the property bag and model tables.
Parameters
true to clean the client_info table, false otherwise. False on default
true to clean local (non-synced) models, false otherwise. Reset all models
Synchronous Return:
Method Access:
Rho.ORM.databaseFullReset(BOOLEAN resetClientInfo, BOOLEAN resetLocalModels)
Deletes all records from the property bag and model tables. Logout the user from RhoConnectClient. For examples, see Resetting the Database in Using the Local Database with ORM.
Synchronous Return:
Method Access:
Rho.ORM.databaseFullResetAndLogout()
Deletes all records from the property bag and model tables for the model names passed in parameters.
Parameters
Properties map.
Array of models names to reset.
If set to true, client_info table will be cleaned. False on default
If set to true, local(non-synced models) will be cleaned. Reset all models
Synchronous Return:
Method Access:
Rho.ORM.databaseFullResetEx(HASH propertyMap)
Deletes all records from the property bag and model tables. Logout the user from RhoConnectClient and erase all RhoConnectClient device information. Equivalent to ORM::ORM.databaseFullReset(true) followed by RhoConnectClient.logout.
Synchronous Return:
Method Access:
Rho.ORM.databaseFullclientResetAndLogout()
Reset only local (non-sync-enabled) models.
Synchronous Return:
Method Access:
Rho.ORM.databaseLocalReset()
Export db
Synchronous Return:
Method Access:
Rho.ORM.export()
Returns the current sync client id.
Synchronous Return:
Method Access:
Rho.ORM.getClientId()
Returns a model.
Parameters
Name of the model you want returned.
Synchronous Return:
Method Access:
Rho.ORM.getModel(String modelName)
Returns true if any of the Rhodes model objects have local database changes that need to be synchronized, false otherwise.
Synchronous Return:
Method Access:
Rho.ORM.haveLocalChanges()
Import db
Parameters
The name of the zip file
Synchronous Return:
Method Access:
Rho.ORM.import(STRING zipName)
var productModel = Rho.ORM.addModel(function(model){ model.modelName("Product"); model.enable("sync"); model.property("name","string"); model.property("brand","string"); model.property("price","float"); model.set("partition","user"); }); // create model object and save it to database var product = productModel.create({ brand: 'Apple', name: 'iPhone5', price: 199.99}); // read product from database var product = productModel.find('first'); product.get('brand'); // Apple product.get('name'); // iPhone5
// The model 'Product' must have been defined in JavaScript execution earlier // in order for 'getModel' to work properly. // The models generated in RhoStudio, are not accessible in JavaScript unless // the classes are defined via the Rho.ORM.addModel api // Get a model by its name after it has been added var productModel = Rho.ORM.getModel("Product");
Rho.ORM.databaseFullResetEx({'models' : ['Product', 'Customer'], 'reset_client_info' : true, 'reset_local_models' : true}