Skip to main content

Data Object Model

The Data Object Model is a data structure designed specifically for the pro-code development mode, similar to a DTO (Data Transfer Object), also known as a Tableless Model.

It is customized by developers according to specific business requirements and does not directly map to or associate with any database tables. The Data Object Model is primarily used in business logic such as service functions, event handling, and process orchestration for structured expression, transmission, and conversion of data. Through Data Object Models, developers can flexibly define multi-layer nested and complex combined data structures, achieving standardized data interaction between different modules and improving code maintainability and reusability.

Applicable Scenarios

Complex Parameter Transmission: Encapsulating complex data structures as input/output parameters for service functions and workflow nodes.
Cross-Module Data Interaction: Unifying data exchange formats between different business modules to implement standardized interfaces.
Temporary Data Encapsulation: Used for temporary data display in UI components (such as tables and forms) without the need for persistent storage.
Business Logic Decoupling: Decoupling data dependencies between frontend/backend or services by defining independent data contracts.

The hierarchical structure of the Data Object Model is Meta (models.Meta) → Type (models.ObjectModelType) → Instance.

Model Directory Structure

Each model element uses an independent folder with the path rule: [App Root Directory]/models/[Model Name]

[App Root Directory]/models/ResultModel/
├── e.json # Model element declaration file
├── model.py # Model element implementation file
└── __init__.py # Initialization file for the package where the model element resides

e.json Declaration File

e.json
{
"backendBundleEntry": ".",
"title": "General Result Object",
"type": "models.ObjectModelType",
"functionList": []
}

model.py Implementation File

The Data Object Model inherits from the ObjectModel class in the models.ObjectModelType package.

model.py
from datatypes.Meta import datatypes
from models.ObjectModelType import ObjectModel

class ResultModel(ObjectModel):
# Define data structure fields
code = datatypes.Integer(title="Status Code", default=200)
message = datatypes.Stext(title="Message")
data = datatypes.Json(title="Business Data")
success = datatypes.Boolean(title="Success", default=True)

__init__.py Initialization File

__init__.py
from .model import ResultModel

Model Fields

The field definitions of the Data Object Model are completely consistent with the Data Table Model, supporting all standard data types. Fields are only used to define data structures in memory and will not generate database table structures.

For a detailed list of field types, please refer to the Field Types Documentation.

# Example: Defining a user information transfer object
nick = datatypes.Stext(name="nick", title="Name")
phone = datatypes.Phone(name="phone", title="Phone")
email = datatypes.Stext(name="email", title="Email")
address = datatypes.Address(name="address", title="Address")

Model Functions

The Data Object Model shares a completely consistent API interface definition with the Data Table Model. This means that in service functions, frontend components (such as tables, forms), or other business logic, the way to call a Data Object Model is exactly the same as calling a regular Data Table Model.

Since the Data Object Model does not have underlying database table support, its default CRUD functions (such as create, save, delete, etc.) only operate in memory or perform no persistence actions. To endow the model with actual business capabilities (such as integrating with external APIs, reading/writing caches, processing complex calculations, etc.), developers need to rewrite the corresponding built-in functions in model.py according to business requirements.

Guide to Rewriting Common Functions

The parameter definitions of each function are consistent with the Data Table Model. For detailed descriptions, please refer to Data Table Model - Built-in Functions.

Function NameDescriptionCommon Rewriting Scenarios
saveSave DataUsed with get to synchronize object instance modifications to external systems.
deleteDelete DataDelete data corresponding to the current object instance.
createCreate DataCall external APIs to submit new data; initialize complex objects in memory.
updateOrAddConditional Update or AddDetermine whether to add or update external data based on business logic.
createOrUpdateManyBatch Create or UpdateBatch process data import or synchronization to external systems.
updateByPKBatch Update by Primary KeyCall external APIs to batch update data.
deleteByPKBatch Delete by Primary KeyCall external APIs to batch delete data.
updateByFilterBatch Update by ConditionBatch update external system data based on specific conditions.
deleteByFilterBatch Delete by ConditionBatch delete external system data based on specific conditions.
queryPagination QueryIntegrate with external APIs to get list data; construct temporary data lists in memory.
getGet Single DataIntegrate with external APIs to get details; read data from cache.
groupByGroup StatisticsPerform group statistics on memory data or external data.
getFieldDataGet Field Value ListGet data sources for dropdown options.
statisticFieldDataField StatisticsPerform statistical calculations on data dimensions.
getExportDataExport DataCustom logic for retrieving export data.
aggregateAggregation CalculationExecute custom aggregation calculation logic.
resetModelDataClear DataClear cache or reset external system test data.
getCompareResultData ComparisonExecute complex Q expression matching logic in memory.

Implementation Example

The following example shows how to integrate a Data Object Model with a simulated external API by rewriting the query and create methods.

Rewriting the query Method

When a UI component (such as a table) loads data, the query method is automatically called.

    @classmethod
def query(cls, filter=None, fieldList=None, orderList=None, page=1, size=20, level=2):
"""
Rewrite the query method to simulate retrieving paginated data from an external API
"""
# 1. Parse the filter parameter (if query conditions need to be supported)
# ...

# 2. Simulate calling an external API
# api_result = external_api.get_users(page=page, size=size)

# Construct fake data for demonstration here
data_list = []
start_id = (page - 1) * size + 1
for i in range(size):
data_list.append({
"id": start_id + i,
"name": f"User_{start_id + i}",
"status": "active"
})

# 3. Return a result structure conforming to JitORM specifications
return {
"rowDatas": data_list, # Data list
"totalCount": 100 # Total record count (for pagination)
}

Rewriting the create Method

When using a form component to submit new data, the create method is automatically called.

    @classmethod
def create(cls, rowData, triggerEvent=1):
"""
Rewrite the create method to process data submission logic
"""
# 1. Data validation or preprocessing
if rowData.name.isNull():
raise Exception("Name cannot be empty")

# 2. Simulate calling an external API to create data
# new_id = external_api.create_user(rowData)

# 3. Return the complete data object containing the new ID
# Note: Must return complete dictionary data for frontend state updates
rowData.id.value = 999 # Assume ID returned by external system
return rowData

Custom Functions

The most common scenario for Data Object Models is defining business processing functions.

1. Declare the function in e.json:

{
"functionList": [{
"name": "processData",
"title": "Process Data",
"args": [{"name": "input", "dataType": "Stext"}],
"returnType": "Stext"
}]
}

2. Implement the function in model.py:

    def processData(self, input):
# Business logic processing
if input.value == "valid":
return "Success"
else:
return 'Failed'
JitAI AssistantBeta
Powered by JitAI