Data sources
Last updated
Was this helpful?
Last updated
Was this helpful?
The data sources you add to an app serve as storage. An object class data source is based on an defined in the . It can be , where the contained objects are a direct representation of the data read from the database. A data source can also be , allowing you to work with objects in a temporary state before storing them in the database. For bulk operations, you might need which offer more efficient direct access to the database.
Other types of data sources are also available, for and . There are also a number of in every app.
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 . Objects created, updated, and deleted in the data source are persisted immediately.
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 .
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 .
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 for more information.
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 , , and action nodes with the data source to manipulate the data.
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.
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.
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.
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.
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
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.
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.
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.
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.
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 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
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 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.
For example, with an Orders
data source as a data connector, you could use the 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.
An enum data source is a way to directly expose an 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 components.
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 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 with Operation Type Toggle selection
.
By default the data source will be . You can configure it to be a or .
Create a 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.
Add .
Add .
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 .
The maximum number of objects to read into the data source on first read. This number can be altered at runtime using the .
This allows you to do bulk directly towards the database without having to read or keep the data in the data source.
When selected, no data in this data source will be stored in the database unless a is run.
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 . 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 , the changes are not pushed to Data Sources with Initially Subscribe to Updates. - 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 Subscribe to Updates. - If (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.
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 .
Add .
The that should apply if Enabled equates to true.
The most secure approach is to use standard on a data source or . These filters are evaluated on the and prevent unauthorized data from being transmitted.
Sorting applied directly on a data source can not be used on conjunction with the .
An to sort on.
Specify which data source contains the data for a 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 in larger apps.
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 .
The type of data allowed to be stored in this property. See .
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 .
Function
: A 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.
Available for Function property type. A that calculates and returns a value at runtime.
Object class properties are the properties you have defined for the in the , as well as .
Data source object properties are built-in properties available for each in the data source.
The index (order) of an object in the data source. Objects in data sources are . 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.
The object is not .
The object is .
Data source attributes describe the state of the data source, for example if the data source is empty or how many are in the data source.
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 .
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 with Run Asynchronous selected and the selection leads to a change in dependent data sources.
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 .
The data source contains no .
The data source contains at least one .
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 .
The number of in the data source.
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 .
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 .