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.

pageCalendar data sources

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

PropertyDescription

Name

A descriptive name for the data source. Use the singular for single-cardinality data sources and plural for many-cardinality data sources. For runtime data sources, you might like to add (runtime) or (temp) to the end of the name for quick identification.

Object Class

Read only. The object class the data source is based on.

Cardinality

Whether the database can hold one or many objects.

A data source of cardinality one is often used in conjunction with Runtime Only for creating new objects, or to store an object while it is being edited.

Cardinality many is useful when you want to access to a group of objects, for example to bind to a List or Table component, or to import rows from a CSV file. If this property is set to One, it will be indicated in the data source's icon in lists of data sources.

Filter

Create a filter to restrict which objects are read into the data source from the database. The data source will continuously evaluate this filter. If an object is changed and no longer meets the criteria, it will be removed from the data source.

A data source can be filtered on another data source. If you have two data sources Projects and Tasks, you can add a filter to Tasks such as Task.Project EXISTS IN Projects. Only tasks with a reference to one of the objects contained in Projects will be populated. Most data sources should have a filter, for both security and performance reasons. A data source should only contain the objects a user should be allowed to see given their role. Additionally, too many objects will degrade app performance.

Read All Objects

Populate the data source with all objects in this Object Class. Selecting this option will result in a warning, see Filter above.

Client Filters

Sorting

Add sorting.

Initially Skip Object Count

The number of objects to skip when objects are first read into the data source. For example, if Skip is set to 2, the first 2 objects in the database that would normally qualify for the data source are ignored. This number can be altered at runtime using the Set data source attributes action node.

Initially Limit Object Count

The maximum number of objects to read into the data source on first read. This number can be altered at runtime using the Set data source attributes action node.

Data Connector

When selected, no data will be read into the data source. The data source will instead operate as a direct connection to the database.

This allows you to do bulk CRUD operations directly towards the database without having to read or keep the data in the data source.

Runtime Only

When selected, no data in this data source will be stored in the database unless a Persist objects action node is run.

Deleting an object from a runtime data source will only remove the object from the data source. It will not be deleted from the database.

Auto Create

Available for single-cardinality runtime-only data sources. When selected, a new object will be created in the data source on app load and when the data source is emptied by removing an object.

Initially Subscribe to Updates

The data source will update when a change is made by another user. This means a refresh is not required to see changes made by others to the objects you are viewing. this should only be used when necessary, because it may have a performance impact. If this property is selected, it will be indicated in the data source's icon in lists of data sources. This property can be altered later using the Set data source attributes action node. Important notes: - We do not recommend using Subscribe to Updates as the only concurrency or data-refresh mechanism for applications with critical needs for instant live sync between clients. For example, if the main feature of your app is that data is instantly live in all clients, such as in a booking system or a multi-user quiz app, you cannot only rely on Subscribe to updates, since the feature does not have a 100% delivery guarantee. - When objects are updated through a Data Connector Data Source (see info about Data Connector a few rows above), the changes are not pushed to Data Sources with Initially Subscript to Updates. - If Conditional Permissions (with conditional read-permissions) have been set up for an Object Class, Initially Subscribe to Update will not work for Data Sources of that Object Class.

Initially Disabled

The data source will be disabled when the app is loaded and as a consequence will be empty.

This can be used for performance optimization by lazy loading data. For example, if you have a data source Company Log and you only need this data when the user clicks a View History button, you can have the data source initially disabled and enable it if the user clicks the button. This property can be altered at runtime using the Set data source attributes action node.

Reference Data Sources

Description

A longer description of the data source. For your own reference.

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.

PropertyDescription

Name

A reference for the filter.

Enabled

Set the filter to be enabled according to a data binding, condition, or function.

Filter

The filter that should apply if Enabled equates to true.

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.

PropertyDescription

Sort Field

An object class property to sort on.

Sort Order

Whether the sort should be ascending or descending. Ascending will sort numbers from smallest to largest and strings from A–Z. Descending will sort in the opposite direction.

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.

PropertyDescription

Reference

The referenced object class.

Data Source

The data source that contains the data for the referenced object class.

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.

PropertyDescription

Name

The name used throughout Appfarm Create to refer to this property. This name can be changed at any time without technical consequences.

Node Name

The key that is used to store the property in memory.

Description

A longer description of the property. For your own reference.

Data Type

The type of data allowed to be stored in this property. See data types.

Cardinality

If the Data Type is set to a reference to an Object Class or an Enumerated Type, you have the option to define Cardinality. The default is One, but you may also select Many (storing an array of references instead of a single reference). Read more on the Cardinality setting in the Object Class Properties section here.

Property Type

An runtime property can be either a value or a function.

  • Value: A primitive value that can be read and updated.

  • Function: A function that calculates a value at runtime. For example, a function that multiplies the values of two other properties and returns a total. If the properties change, the function will re-run.

Value on Create

Available for Value property type. A default value to set for the property when the app is loaded.

Function

Available for Function property type. A function that calculates and returns a value at runtime.

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.

PropertyData typeDescription

Index

Integer

The index (order) of an object in the data source. Objects in data sources are zero-indexed. The first object is at index 0, the second is at index 1 and so on. The last object will have an index equivalent to Object Count minus one. Important: If you wish to implement user-sorting, you should define a separate integer property in the object class and use that to store the sort order.

Is Even In Data Source

Boolean

The Index of the object is an even number.

Is First In Data Source

Boolean

The object has an Index of 0.

Is Last In Data Source

Boolean

The object has the highest index of all objects.

Is Not Selected

Boolean

The object is not selected.

Is Selected

Boolean

The object is selected.

Object State

Boolean

Available for runtime-only data sources. The persist state of the object. An object will return one of the following values:

  • New: The object has never been persisted to the database.

  • Updated: The object exists in the database, but has changes that have not been persisted.

  • Synchronized: Any changes have been persisted and the object is in sync with the database.

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.

PropertyData typeDescription

Data Ready

Boolean

The data source has finished processing data. This property is not often used as most data operations are synchronous and an action node won't run until the previous action node's data operations are complete. Data Ready can be useful when you run the Set selection action node with Run Asynchronous selected and the selection leads to a change in dependent data sources.

Disabled

Boolean

The data source is disabled and as a consequence is empty. This property can be set by selecting the Initially Disabled property, or using the Set data source attributes action node.

Has No Selected Objects

Boolean

The data source contains no selected objects.

Has Selected Objects

Boolean

The data source contains at least one selected object.

Is Empty

Boolean

The data source contains no objects.

Is Not Empty

Boolean

The data source contains at least one object.

Limit

Integer

The maximum number of objects that can be in the data source. This property can set by entering a value for the Initially Limit Object Count property, or using the Set data source attributes action node.

Object Count

Integer

The number of objects in the data source.

Selected Objects Count

Integer

The number of selected objects in the data source.

Skip

Integer

The number of objects to skip when reading objects into the data source. For example, if Skip is set to 2, the first 2 objects in the database that would normally qualify for the data source are ignored. This property can set by entering a value for the Initially Skip Object Count property, or using the Set data source attributes action node.

Subscribe To Updates

Boolean

The data source will update when a change is made by another user. This property can be set by selecting the Initially Subscribe To Updates property, or using the Set data source attributes action node.

Total Objects Count

Integer

The total number of objects that qualify for the data source. This number may differ from Object Count because it includes objects excluded from the data source due to Client Filters, Limit, and Skip.

Last updated