Working with MetaData

From Lianjapedia
Jump to: navigation, search
Bm-noteicon.png
Quick Start Guide

Select the "Data" workspace if it is not already selected.
Select the "Database" Tab.
Double click a database name and all tables in the database will be displayed.
Click on a table in the tables panel.
Click on a column in the columns panel.
Click the small edit icon in the footer panel of either the database, table or columns panel.
The MetaData Editor will be displayed.


Overview

The MetaData Editor allows you to add, edit and delete database, table and column MetaData.

  • To add a new MetaData attribute, specify a name and a value and optionally a condition in the entry fields then click Add. The new attribute will be added to the grid.
  • Click the grid row of an existing attribute to load its details into the entry fields. From here the details can be edited - click Update when complete - or the whole attribute can be deleted by clicking Delete.
  • Click Clear to clear the entry fields.
  • Click Done to save changes and exit the MetaData Editor, or Cancel to abandon the changes and exit.

See Lianja MetaData API for an overview of creating and using Custom MetaData.

Database MetaData

Database MetaData



Open the database (double-click) then switch back to the Databases tab and click the 'MetaData editor' icon at the bottom of the panel to open the MetaData Editor.


Note that the databasemetadata() function returns database MetaData and that this can be loaded into an object using the metadata_decode() function.


Table MetaData

Table MetaData


Select or open the table, here 'products', then click the 'MetaData editor' icon at the bottom of the panel to open the MetaData Editor.


Note that the tablemetadata() function returns table MetaData and that this can be loaded into an object using the metadata_decode() function.


The tablemetadataversion() function returns the table's MetaData version number. This number is incremented each time a MetaData change is made in the MetaData Editor or using the alter table command. In custom code, it can be compared with the section MetaData version attribute to apply new MetaData to a section when required.


Table MetaData: Conditional Attributes



Here, additional attributes have been added and include conditions based on record contents.


Note the use of OData Operators in the conditions.

Applied Table MetaData



Here, an App uses the products table in a Form Section.


The MetaData associated with the products table has been automatically applied to the section.

Column MetaData

Column MetaData


Select the column, here products.productid, then click the 'MetaData editor' icon at the bottom of the panel to open the MetaData Editor.


Note that the columnmetadata() function returns column MetaData and that this can be loaded into an object using the metadata_decode() function.


Bm-noteicon.png
Pro Tip

When you associate metadata with columns like this, you typically define UI attribute names and values. Wherever the column is used in any App, when the table is opened the metadata is read and the attributes are them applied to the UI element. Changes to the metadata are automatically applied across all Apps. No code changes are required. This provides a powerful means of data binding with associated business logic all without coding.

Column MetaData



Another example of column MetaData, here for products.supplierid.


Applied Column MetaData



Here the products.productid column MetaData has been automatically applied to the FormItem in the Section.


Applied Column MetaData



And here is the products.supplierid column with its MetaData applied.


Custom MetaData

In the Table and Column MetaData examples above, the attributes have been defined with the 'section.' and 'formitem.' prefixes. These will be automatically applied to Sections and Formitems (in Form and Canvas Sections). In Lianja 5.0 and above, column metadata does not require attributes to be prefixed with formitem. If the metadata name does not contain a '.' then the key is assumed to be an attribute name and the attribute value is applied to a formitem that is bound to that column.

Custom MetaData can be applied in a setupUI.prg script, run when the App is loaded.

The Lianja system object and the PageBuilder, Section and FormItem objects also have applyMetaData() methods that can be used in event delegates to apply MetaData after data changes.

For more details, see the Lianja MetaData API Guide.

See Also

ACLASS(), ADDPROPERTY(), ALTER TABLE, AMEMBERS(), COLUMNMETADATA(), COMPOBJ(), CREATE TABLE, CREATEOBJECT(), DATABASEMETADATA(), DEFINE CLASS, DISPLAY CLASSES, DODEFAULT(), FOREACH, JSON_DECODE(), JSON_DECODE_FILE(), JSON_ENCODE(), Lianja MetaData API, LIST CLASSES, LOADOBJECT(), METADATA_DECODE(), METADATA_ENCODE(), METADATA_FINDTYPE(), NEWOBJECT(), OBJECT(), PRINT_JSON(), PRINT_HTML(), PRINT_R(), PRINT_XML(), REMOVEPROPERTY(), REQUIRE_ONCE(), SAVEOBJECT(), SQL SELECT, TABLEMETADATA(), TABLEMETADATAVERSION()