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.
Good to know
Changes to data which happen through Data Connectors (e.g. creates, updates, deletes) will not trigger Subscribe to Updates functionality.
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.
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
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
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
Initially Skip Object Count
Initially Limit Object Count
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.
Runtime Only
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
Initially Disabled
The data source will be disabled when the app is loaded and as a consequence will be empty.
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.
Name
A reference for the filter.
Enabled
Set the filter to be enabled according to a data binding, condition, or function.
Filter
Remarks regarding Read All Objects & Client Filters
Using Read All Objects or Client Filters may not align with security best practices. Client Filters are applied after the data has been transmitted from the server. This means that some browser developer tools can inspect the unfiltered data as it is transmitted from the server to the client. Likewise, datasources with Read All Object will also be available for inspection in some browser developer tools. This is important to keep in mind when filtering data on the client, either in form of Client Filters or UI filters.
The most secure approach is to use standard Filters on a data source or Conditional Permissions. These filters are evaluated on the server rather than the client, and prevent unauthorized data from being transmitted.
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.
Sort Field
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.
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.
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
Cardinality
Property Type
An runtime property can be either a value or a function.
Value
: A primitive value that can be read and updated.
Value on Create
Available for Value property type. A default value to set for the property when the app is loaded.
Function
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.
Index
Integer
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
Is Selected
Boolean
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.
Data Ready
Boolean
Disabled
Boolean
Has No Selected Objects
Boolean
Has Selected Objects
Boolean
Is Empty
Boolean
The data source contains no objects.
Is Not Empty
Boolean
The data source contains at least one object.
Limit
Integer
Object Count
Integer
The number of objects in the data source.
Selected Objects Count
Integer
Skip
Integer
Subscribe To Updates
Boolean
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
Was this helpful?