Wakanda Online Documentation Center

Datastore Classes

Datastore Classes  

  

The datastore class is a type of structure that can contain attributes and relation attributes (links between datastore classes) in order to conceptually describe its data and how they all interact with each other as well as methods to interact with the data in your model.

Once you create a datastore class, you can add attributes and methods to it.

When working in the workspace, the datastore class has a title bar at the top offering you many options to define how it is displayed without modifying the datastore class itself.

The toolbar contains three icons:

  • The and icons toggle the attribute type names column in the datastore class.
  • The icon modifies the display settings for the datastore class.
  • The icon hides the datastore class in the workspace.

You can, however, rename the datastore class name by double-clicking the title bar. For more information, refer to the Rename a datastore class page in the Wakanda User Guide.

The and icons allow you to toggle the type names column, containing the names of the attribute types as well as the Applies To drop-down list for datastore class methods. The datastore class, when the third column is hidden, appears in the workspace as shown below:

 Clicking on the icon displays the following menu:

  • Extend {Datastore Class Name}: This button allows you to extend the datastore class. For more information, refer to the Extending a Datastore Class section.
  • Panel Color: This button allows you to modify the color of the datastore class’s title bar. When you click on it, the following window appears allowing you to select a color:

    You can also enter a color in the Hex field by entering a color’s hexadecimal value. 

    The icon next to the datastore class name in the Datastore Classes Area also displays the selected color:
  • Expand/Collapse Panel: Expands and collapses the panel. When the panel is collapsed, only the datastore class’s title bar appears:
  • Fit Panel to Content: Readjusts the size of the datastore class panel so that when you reduce its size, it will be enlarged to show its contents. If the panel appears as the one below, this option allows you to see the panel in its entirety:
  • Show/Hide Storage, Calculated, Alias, or Relation Attributes: Toggles the different attributes (storage, calculated, alias, or related) in the datastore class.
  • Show/Hide Methods: Toggles the datastore class methods displayed at the bottom of the datastore class in the workspace. When they are hidden, the datastore class appears as such:
  • Show/Hide Removed Attributes, Inherited Attributes, and Inherited Methods: These three options appear when you have a derived datastore class. You can toggle the display of these elements in the datastore class panel.

You can show or hide a datastore class in the workspace. To hide it, either select Hide from the datastore class’s contextual menu in the datastore class list or click the icon in the datastore class’s toolbar. To show it again in the workspace, click on the datastore class’s name in the Datastore Classes area.

In the Properties tab, you can modify the datastore class’s properties:

  • Primary key: Defines one of the attributes as the primary key for the datastore class. From the drop-down list, you can select another valid attribute in the datastore class. For more information, please refer to the Modifying the Primary Key section.
  • Class name: Datastore class name. If you rename the datastore class, refer to the Renaming a Datastore Class section below.
  • Collection name: Collection for the datastore class. You can modify the default value, however it cannot be left blank.
  • Allow global access: By default, this option is unchecked and therefore the datastore class is published locally. When a datastore class is published locally, you can access it by using the “ds” prefix, i.e., ds.Employee. However, when it is published globally, you can access the datastore class simply by using its name, i.e., Employee.
    Note that this option can also be set at the model level and it then applied to all datastore classes (see Model Properties).
  • Allow stamp override: By selecting this option for your datastore class, you can allow an entity to be modified regardless of its internal stamp. Normally, when you save an entity, its internal stamp must be the same as the one you send to it to save it. To use this property, you must also pass true to the overrideStamp option to the save( ) (Datasource) and save( ) (Dataprovider) functions (both in the client-side JavaScript API).
  • Scope: Modifies the scope (public or public on server ()) of the datastore class. A public datastore class can be accessed from anywhere while a public on server datastore class can only be accessed on the server.
  • Restricting query: A query that restricts the entities returned for a datastore class. Every time data is requested for a datastore class, this query is executed after the one inserted in the On Restricting Query event (if one was added). You can also use Wakanda’s system placeholders (:$userID, :$userName, or :$currentDate) in your queries. For example, you could write “employee.ID=:$userID” as the restricting query. For more information about the system variables, please refer to the “:$ Placeholders for System Variables” section in the “Defining Queries (Server-side)” chapter. For more control, you can also add a more complex query in the datastore class's On Restricting Query event described in the Datastore Class Events section below. For more information, refer to the "Programming Restricting Queries" section in the "Datastore" chapter.
  • Default top size: Default top size for REST requests made to the server. The number you specify is the number of entities retrieved for the datastore class. If this property is left blank, the default value of 40 is used.
  • Notes: Notes that you can store with your datastore class for private use.

By default, each datastore class is created with an ID attribute as the primary key, having the Mandatory, Autosequence and Unique properties checked as well as the Index Kind set to Auto by default.

In the datastore class’s panel, the attribute defined as the primary key is bold and underlined with the icon next to it. To change the primary key, you can do so by either clicking on the icon next to the new attribute name or by selecting an attribute in the Primary Key drop-down menu in the datastore class’s Properties tab. Only the attributes with valid types (Longint, Long64, Number, String, or UUID) are displayed in the drop-down menu.

You can also remove the primary key from your datastore class by clicking on the icon next to the attribute; however, at least one attribute must be defined as the primary key in your datastore class.

In this area, you define the permissions for a specific datastore class:

You select a group from the dropdown menu to give it permissions to perform any of the following actions for a specific datastore class. For more information, refer to Permission Actions.

In the For Methods area, you can define the permissions for the datastore class methods in the datastore class.

You select a group from the dropdown menu to give it the permission to perform one or more of the following actions applied to the methods in the datastore class. For more information, refer to Permission Actions.

The Force Temporary Permissions checkbox allows you to temporarily override a particular setting, if you want to test your project for example. For more information, please refer to the "Forcing temporary permissions " section.

 

If you enter a space, it will be replaced by an underscore. The Class Name and the Collection Name must be unique and start with a letter, and can contain only numbers and letters. You can also include accented and non-Roman letters. For more information, please refer to the Naming Conventions section.

Note: Datastore class names are case-sensitive: “Employee” and “EmpLoyee” are not equal.

You can add code that will be automatically executed during the following events for a datastore class:

  • init: Executes when a new datastore entity is created, but after any auto sequence values are assigned.
  • load: Executes just after a datastore entity is accessed and before it is delivered to the calling routine.
  • validate: Executes when a datastore entity is validated, which also occurs during save, and can reject the validation if needed.
  • save: Executes before a datastore entity is saved and can reject the save if necessary.
  • remove: Executes before a datastore entity is deleted and can reject the deletion if necessary.
  • restrict: In this event, you return a collection to restrict the data for a datastore class. The query you include in this event will be called before the one you included in the Restricting query property. For more information, refer to the Programming Restricting Queries section in the "Datastore" chapter.
  • validateremove: This event is triggered before removing an entity on the server.
  • clientrefresh: This event is executed after the client calls serverRefresh( ).

Note: For more information regarding the datastore class events, refer to DatastoreClass Events.

When you click the icon next to an event, you will be prompted to define in which JS file you want to insert the code:

The code that appears in the file corresponds to the event you selected to add:

model.Company.events.save = function(event) {
    // Add your code here;
};

Note: For information regarding the event parameter, refer to Event parameter.

To open this JavaScript file again, click on the icon to go directly to it. If you want to delete the event, you must do so in the JS file in which you wrote the code.

For more information regarding each of the datastore class events, refer to the DatastoreClass Events API.

Note: When developing on the client, keep in mind that the init event is triggered when an entity is created on the server. Therefore, datasource methods such as newEntity( ) or Button widgets having the “Create” action will not trigger this event. When the client attempts to save the entity, an update request is then sent to the server and an entity is created in memory on the server thus triggering the init event.

The listener function accepts a single event object as parameter. When the function is called, the parameter is filled with several properties that allow you to write generic code:


PropertyTypeValues
event.eventKindstring"init", "load", "remove", "restrict", "set", "save", or "validate"
event.attributeNamestringName of the attribute on which the event is set (when applicable)
event.dataClassNamestringName of the datastore class on which the event is set
 
 

 You can define a method for a datastore class either in the Datastore Class’s Methods tab or at the bottom of the datastore class displayed in the workspace:

 

To edit the code for the method, click on the icon.

Note: For more information, please refer to the Datastore Class Methods section.

Extending a Datastore Class  

Modified in v11

When you extend a datastore class, a new datastore class is created that includes not only its attributes, but also its methods. This new datastore class is called the “derived” datastore class and its attributes and methods are “inherited” from the extended datastore class.

This concept allows you to build applications using basic datastore classes that can be extended to allow for specialized data schemes. For example, if we create a “Person” datastore class, it can be extended into other datastore classes, like “Student” and “Teacher” because many of the same attributes are in all three of these datastore classes.

In the settings, you can show/hide from the datastore class panel the removed inherited attributes, inherited attributes, and inherited methods:

With derived datastore classes, you can:

  • add any types of attributes (scalar, relation, calculated, and alias attributes) to a derived datastore class,
  • override certain properties of the inherited attributes (see below), and
  • remove any inherited attributes from the derived datastore class.
 

 

You can modify the following properties of inherited attributes:

  • Scope
  • Multi-line
  • Limiting length
  • Identifying
  • Format
  • Notes
  • Pattern
  • Max value
  • Min value
  • Default

You cannot modify the following properties for inherited attribute:

  • Type
  • Index kind
  • Unique
  • Mandatory
  • Date only
  • Autosequence
  • Autogenerate (uuid)

 

Home

PROPERTIES 

Theme: Datastore Classes

 
SEE ALSO 

Dev Center - Video - Datastore Class and Attribute Events
Dev Center - Video - Defining a Restricting Query
Dev Center - Video - Defining Data Rules
Dev Center - Video - Extending a Datastore Class