Data sources

The data sources you add to an app serve as object storage. An object class data source is based on an object class defined in the Data model. It can be database connected, where the contained objects are a direct representation of the data read from the database. A data source can also be runtime only, allowing you to work with objects in a temporary state before storing them in the database. For bulk operations, you might need data connectors which offer more efficient direct access to the database.

Other types of data sources are also available, for calendars and enums. There are also a number of built-in data sources in every app.

Database-connected and runtime-only data sources

Apps use primarily two types of object class data sources, database-connected and runtime-only. In general, database-connected data sources are used when you need to read data directly from the database, while runtime-only data sources are used as temporary storage to create and edit objects before they are saved to the database.

By default, an object class data source is database connected. A selection of objects are automatically read into the database according to the Filter property (or all objects if Read All Objects is selected) and the data source will continuously monitor this filter. Objects created, updated, and deleted in the data source are persisted immediately.

Good to know

If you create a new object in a database-connected data source, and the new object does not qualify for the data source according to the filter, the object will be created and persisted, but will not be present in the data source.

However, if you want to work with data in a temporary state you can use a runtime-only data source. This can be useful for importing data or storing edits before saving the changes to the database. A data source is made runtime-only by selecting Runtime Only in the data source properties.

Objects can be created, read, updated, and removed from runtime-only data sources, but these operations must be done explicitly using action nodes. One exception is creating objects, which can be made automatic in single-cardinality data sources by selecting Auto Create in the data source properties. When auto create is enabled, a new object will be created in the data source on app load and when the data source is emptied by removing an object. To save a new or updated objected to the database, you must use the Persist objects action node.

Good to know

If you delete a persisted object from a runtime-only data source it only removes the object from the data source. It will not be deleted from the database.

Runtime-only data sources are quite performant as they are not continuously communicating with the database. It is recommended to use runtime-only data sources to manage objects when possible, particularly when performing data modifications in iterations. See How to optimise your app performance for more information.

Data connectors

An object class data source configured as a data connector has a direct connection to the database. Data connectors are useful for performing bulk data manipulation operations directly towards the database without having to read or keep the data in the data source.

As no objects are actually contained in the data source, it can’t be used to display data in the UI. However, you can use the Create object, Update object, and Delete objects action nodes with the data source to manipulate the data.

For example, with an Orders data source as a data connector, you could use the Update object action node to set Order.Status to Active for a filtered selection on Orders where Order.Status HAS NO VALUE. All orders in the database without a status will be updated immediately.

Calendar data sources

A calendar data source is a special type of data source for working with time periods. A typical use case for a calendar data source is when you need to iterate over a number of time periods, for example all the months of a year, or every hour of a day. You might do this to group data by time period, for example all orders placed in a given month.

Enum data sources

An enum data source is a way to directly expose an enum that's made directly available to an app. This can be useful for filtering data in the UI based on multiple enum values, using the Chip group or Multi select components.

Example: Filter by event type

You have a view with a List component containing Events and you want to allow users to select one or more Event type values (an enum added as a property to the Event object class) and view only events matching the selected types.

You can add the Event type enum as an enum data source and bind it to a Chip group component. Then you can attach an action to the chip group's On Click event handler which runs a Set selection action node with Operation Type Toggle selection.

On the list, you can add a conditional filter which is enabled if Event type.Has selected objects EQUALS true and a filter Events.Event type = Event type (Context/Selected).

You could also add a conditional property to the chip group, setting a new color if the Event type.Is Selected EQUALS true.

Usage

To add an object class data source to an app:

  • Open the app and navigate to Data.

  • In the App Data panel, click the + icon.

  • Select one or more object classes for which you'd like to create data sources.

  • Click Add.

  • By default the data source will be database connected. You can configure it to be a data connector or runtime only.

To add an enum data source to an app:

  • Open the app and navigate to Data.

  • In the App Data panel, click the down arrow icon.

  • Select Add Enum Data Source.

  • Select one or more enums for which you'd like to create data sources.

  • Click Add.

General properties

Client filters

Add one or more filters to a data source that can be enabled or disabled at runtime. This is useful if you want to provide a user with the ability to filter data from the UI. Client filters are applied in addition to one specified in the Filter property.

For example, say you have a data source Projects, where each project has a status of either New, Ongoing, or Complete. You can display the projects in a list and add UI components to enable the user to dynamically filter the data source (and thereby the list) to contain only the projects with a specific status.

One advantage to using client filters on a data source over conditional filters on a UI component is that you can easily access the Object Count If this property is selected, it will be indicated in the data source's icon in lists of data sources.

Sorting

Apply one or more sorting rules to a data source that will be continuously applied. If multiple rules are added, they will be applied from the top down.

Good to know

Sorting applied directly on a data source can not be used on conjunction with the Sort objects action node.

Reference data sources

Specify which data source contains the data for a reference property in the object class.

Reference data sources allow you to use deep-data bindings for non-persisted references and runtime function references. They are helpful for creating REST-heavy applications and are also an important element for performance optimization in larger apps.

If you have an object class property which references another object class, and your app accesses a property in the referenced object class, this is known as a deep-data binding. If you add a reference to a runtime-only data source, this deep-data binding will not be available unless the object is persisted.

If you are interacting with a persisted object, a generated data source is created in the background, joining the two object classes. This can result in large amounts of extra data being loaded into an app. In the Developer Tools, you may turn on display of these data sources by enabling Include Generated Data Sources.

By adding a reference data source you explicitly specify a data source that contains the data for the referenced object class. This solves the issues above by removing the need for a generated data source and enabling deep-data bindings on non-persisted references.

Example: Customers and Contacts

You two data sources, Contacts and Customers. Contacts has an object class property Customer, which is a reference to the Customer object class. In a Table component listing all contacts, you want to display the customer name. If you add Contacts.Customer.Name as a column in the table, this would create a generated data source joining the contact and customer data.

Since you already have the Customers data source, you can add a reference data source with Reference Customer and Data Source Customers. With the reference data source enabled, the customer data is now read from the Customers data source. You can add any property from the Customer reference, such as Contacts.Customer.Country without any performance impact.

Runtime properties

Runtime properties are data-source specific custom properties available for each object in the data source. The value of a runtime property will exist only in the user's browser and is not saved to the database or shared with other users. A typical use case is to calculate a value based on other properties.

Example: Function to calculate a total

You have a data source based on the object class Order line that includes the object class properties Quantity and Price. You want to automatically calculate the total in your app.

Create a runtime property Total, with Data Type Float and Property Type Function. Create a function that multiplies the quantity property by the price quality and returns the total.

You can then reference the Total property in your UI and it will dynamically update when Quantity and Price are changed.

Object class properties

Object class properties are the properties you have defined for the object class in the Global data model, as well as built-in properties.

Data source object properties

Data source object properties are built-in properties available for each object in the data source.

Data source attributes

Data source attributes describe the state of the data source, for example if the data source is empty or how many objects are in the data source.

Example: Skip objects

You have created a custom list with all objects in a Customers data source using iterating containers. You'd like to add pagination, displaying 10 objects at a time.

Set Initially Limit Object Count to 10 and Initially Skip Object Count to 0. Add a Next page button that triggers an action with the Set data source attributes action node and increase Skip by 10.

Example: Limit objects

You have created a custom list of objects in an Events data source using iterating containers. You would like to implement dynamic loading of data, known as infinity scrolling.

Set Initially Limit Object Count to 20. Add a Load more button at the bottom of the custom list that triggers an action with the Set data source attributes action node and increase Limit by 20.

Alternatively, you could use the On Viewport Enter event handler on a container to trigger the action. An example of this is available in the Showroom.

Last updated