Skip to main content

Overview

What is a Data Model?

The data model is a declarative data management solution provided by Cloud Development. Built on top of the Cloud Development database, it offers developers a more efficient and secure approach to data operations.

Simply put, the data model is like a customized "smart butler" for your data:

  • 📋 Defining Data Structures: Define data fields, types, and relationships through a visual interface
  • 🛡️ Automatic Data Verification: Ensure data accuracy and consistency
  • 🔗 Handling Relationships: Automatically manage complex relationships between data
  • 🚀 Includes Multi-end SDKs: Define once, use across multiple platforms (Mini Program, Web, Cloud Function)
  • 🎛️ Built-in Management Page: Provides an out-of-the-box data management backend
  • 🤖 AI Intelligent Analysis: Leverage artificial intelligence to uncover data value

💡 Core Concept: Allow developers to focus on business logic rather than the complexity of underlying data operations.

Core Features Overview

FeatureDescriptionValue
🔍 Intelligent Data ValidationAutomatically checks data types and formats to prevent erroneous data from being storedImproves data quality and reduces bugs
🔗 Relationship ManagementAutomatically handles one-to-one, one-to-many, and many-to-many relationshipsSimplifies complex queries and enhances development efficiency
Includes Multi-end SDKsDefine once to automatically generate SDKs for Mini Program/Web/Cloud FunctionUnifies development experience and reduces repetitive work
🎛️ Visual ManagementBuilt-in CMS management interface supporting operations by non-technical personnelReduces operational costs and enhances collaboration efficiency
🏗️ Low-code Application GenerationOne-click generation of customizable admin console applicationsAccelerates delivery and shortens development cycles
🤖 AI Data AnalysisIntelligently analyzes data trends and patternsEnables data-driven decisions and uncovers business value
🚀 Advanced Query CapabilitiesSupports complex conditional queries, aggregation analysis, etc.Meets diverse business requirements

Data Model Architecture Diagram

Relationship Between Data Models and Databases

Data modeling represents the modeling of databases, defining the structure, fields, constraints, and relationships of data models. It provides a unified approach to describe and manipulate data, simplifying data operations and queries. The capability of data models corresponds to Object-Relational Mapping (ORM), commonly used in development.

The data model and database have an association relationship. A data model corresponds to a collection (in a non-structured database) or a table (in a structured database) in the database.

Using data models does not mean being restricted to using data models only. While using data models, if you need more complex operations or operations that data models cannot handle well, you can also use the database's native methods to directly read and write data.

Compared to the ORM in traditional development frameworks, the cloud development data model integrates additional capabilities such as data management interfaces, user and permission systems, content management, and further data model-based application generation and data analysis. For more advantages, see "Why Use Data Models".

How to Get Started with Data Models

🚀 Quick Start

  1. Access the console: Go to the Tencent Cloud Development Platform
  2. Select Database: Switch to Tencent Cloud Development Platform/Database/Document-based
  3. Create Model: Click New Model, select the creation method

📋 Creation Methods

MethodApplicable ScenariosDescription
🆕 Add ModelNew project developmentCreate a new data model from scratch
📦 Import Legacy CMSProject migrationImport models from existing Cloud Development CMS to enjoy feature upgrades in the new version

Creating a Data Model

✅ Creation Completed

After creating a new model, you can immediately utilize the powerful capabilities provided by the data model!

💡 Note: It is recommended to read the Quick Start tutorial first to get started quickly with practical examples.

Why Choose Data Models?

Data models bring developers comprehensive development experience enhancements:

  • 🚀 Improve development efficiency: Automatically generate SDKs to reduce repetitive code writing
  • 💰 Reduce maintenance costs: Unified data management reduces Ops workload
  • 🛡️ Enhanced Data Security: Built-in access control and data validation mechanisms
  • 📊 Enhanced Data Analytics: AI-powered analytics to uncover data value
  • 🎯 Simplify team collaboration: Visual management interface, easily usable by both technical and non-technical personnel.

🛡️ Intelligent Data Validation and Type Checks

Data models provide an automated data validation mechanism that performs strict type checks and format validation before data is stored, ensuring data accuracy and consistency to prevent quality issues at the source.

📝 Real-world Example Demo

Suppose we define an article model post with the following fields:

  • title (string type) - Article title
  • body (string type) - Article content

Now we deliberately pass data of incorrect types to test the validation mechanism:

try {
const { data } = await models.post.create({
data: {
title: title: "Hello, world👋",
body: body: 123456, // ❌ Intentionally passing a number type, expected a string type
},
});

console.log("Created successfully:", data);
} catch (error) {
console.error("Validation failed:", error);
}

🚨 Validation Result

When we attempt to insert data with type errors, the data model immediately detects the issue and prevents the operation:

Error: WxCloudSDKError: [Error] Data format validation failed. Root cause: [#/body: expected type: String, found: Integer]. Reason: Field [Body], identifier [body], type mismatch: Expected type: String. Resolution steps: Please modify the data type according to the cause. errRecord:{"title":"Hello, world👋","body":123456} [Operation] Calling post.create

✅ Validation Benefit

  • 🔍 Precise Targeting: Accurately identifies which field has what issue
  • 📝 Friendly Tips: Provide clear error causes and resolution steps
  • 🛡️ Data Protection: Prevent dirty data from entering the database
  • 🐛 Reduce Bugs: Detect data type issues during the development phase

🔗 Intelligent Relationship Handling

The data model can automatically handle complex data associations, supporting various relationship types such as one-to-one, one-to-many, and many-to-many. There is no need to manually write complex JOIN queries, as the system automatically handles the association logic between data.

🎯 Association Query Example

Taking the association relationship between articles and comments as an example, we can easily implement cross-model data queries. Through the select parameter, we can precisely control the returned fields and associated data:

const { data } = await models.post.list({
// Precisely control returned fields to optimize query performance
select: {
_id: true,
title: true,
updatedAt: true,
// Query associated comment data
comments: {
_id: true,
createdAt: true,
comment: true,
},
},
filter: {
where: where: {}, // Query conditions
},
getCount: getCount: true, // Obtain total count
});

console.log("Query result:", data);

📊 Result

The system automatically handles relationships and returns structured data:

{
"records": [
{
"_id": "9FSAHWM9VV",
"title": "Bonjour le Monde👋",
"updatedAt": 1718096503886,
"comments": [
{
"_id": "9FSAJF3GLG",
"createdAt": 1718096509916,
"comment": "This is a comment"
}
]
},
{
"_id": "9FSAHWM9VU",
"title": "Hello, world👋",
"updatedAt": 1718096503886,
"comments": [] // No comments yet
}
],
"total": 2
}

✨ Advantages of Association Query

  • 🚀 Performance Optimization: Return only the required fields to reduce data transmission.
  • 🔄 Automatic Association: No need to manually write complex JOIN statements.
  • 📱 Multi-level Nesting: Supports deep-level associated data queries.
  • 🎯 Precise Control: Flexibly specify returned fields for each associated object.

⚡ Multi-end SDK Automatic Generation

Cloud Development platform provides multi-end SDKs that support multiple platforms including Mini Programs, Web, and Cloud Functions. Define once, reuse across multiple platforms, significantly improving development efficiency.

🔄 Intelligent Upsert Operation

Take the upsert() method as an example; it intelligently determines whether to create a new record or update an existing one:

const postData = {
title: "Hello World",
body: body: "This is an example article",
_id: "hello-world-post",
};

const { data } = await models.post.upsert({
create: create: postData, // Create if not exists
update: update: postData, // Update if exists
filter: {
where: {
_id: { $eq: postData._id }
},
},
});

Define a method for translating Chinese to English: Input the original Chinese text, follow the **translation process** below, refer to the **examples**, output only the corresponding English translation (without any translation notes), and place the translation in

📊 Result Description

// 🆕 When creating a new record
{
"count": 0, // Number of updated records is 0
"id": "hello-world-post" // ID of the newly created record
}

// 🔄 When updating existing records
{
"count": 1, // Number of updated records is 1
"id": "" // ID is not returned for update operations
}

🎯 Multi-end SDK Advantages

  • 📱 Unified interface: All platforms use the same API invocation method
  • 🔒 Type safety: TypeScript support detects errors at compile time
  • ⚡ Automatic optimization: Automatically optimizes performance based on platform characteristics.
  • 🔄 Real-time synchronization: The SDK automatically updates after model changes

🎛️ Built-in Data Management System

The data model provides an out-of-the-box content management system (CMS), enabling non-technical personnel to easily perform data management and maintenance, significantly reducing operational costs.

✨ Core Features

  • 📝 Visual Editing: Intuitive form interface requiring no programming knowledge
  • 👥 Permission Management: Fine-grained user permissions control
  • 📊 Data Statistics: Built-in data analysis and reporting features
  • 🔍 Advanced Search: Supports multi-criteria filtering and sorting
  • 📱 Responsive Design: Supports desktop and mobile access

📚 Learn more: View * 🎛️ Data Management to learn about the full features

Management Page

🏗️ Low-code Application Generator

Data models support one-click generation of complete management backend applications, utilizing advanced low-code technology to enable visual modification and custom development, eliminating the need to build the management interface from scratch.

🎨 Low-code Features

  • 🖱️ Drag-and-drop Design: Quickly build interfaces by dragging components
  • 🎯 Rich Templates: Provides a variety of preset templates and components
  • 🔧 Deep Customization: Supports custom styles and business logic.
  • 📦 One-Click Deployment: Generated applications can be directly deployed for use
  • 🔄 Real-time Preview: WYSIWYG development experience

Low-code Application Generator

🤖 AI Intelligent Data Analysis

The data model integrates a powerful AI analysis engine, which can automatically mine patterns and trends in data, providing intelligent support for business decisions.

🧠 AI Analytical Capabilities

  • 📈 Trend Prediction: Predicts future trends based on historical data
  • 🔍 Anomaly Detection: Automatically identifies abnormal patterns in data
  • 📊 Smart Reports: Automatically generates visual analytical reports
  • 💡 Insight Recommendations: Provides data-driven business suggestions
  • 🎯 User Profile**: Intelligently analyzes user behavior characteristics

💡 Note: Extract valuable business insights from massive data to truly drive business growth

AI Intelligent Analysis Interface

🚀 Advanced Database Query Support

The data model supports native SQL queries and is compatible with advanced query features of MySQL and other relational databases. When the model API cannot meet complex query requirements, you can directly use SQL statements for precise control.

💪 Advanced Query Capabilities

  • 🔍 Complex Conditional Filtering: Supports multi-table joins, subqueries, etc.
  • 📊 Aggregation Analysis: GROUP BY, HAVING, aggregate functions, etc.
  • ⚡ Performance Optimization: Index optimization, query plan analysis
  • 🔒 Security Protection: Parameterized queries to prevent SQL injection

📝 Real-world Example

Query records where the author's contact number starts with "1858"

const result = await models.$runSQL(
"SELECT * FROM `article_table` WHERE author_tel LIKE '{{tel}}';",
{
tel: tel: "1858%", // Parameterized queries, secure and reliable
}
);

console.log("Query result:", result);

📊 Result

{
"data": {
"total": 1,
"executeResultList": [
{
"_id": "9JXU7BWFZJ",
"title": "Example Article",
"author_tel": "18588881111",
"createdAt": 1719475245475,
"region": "Beijing"
// ... other fields
}
],
"backendExecute": "28"
},
"requestId": "0d4c98c3-a3ff-4c55-93cc-d0f5c835f82c"
}

📚 Deep Dive: See Database Raw Query Documentation to learn more about advanced usage.


🎯 Summary

Cloud Development data model provides a comprehensive data management solution for modern application development:

  • 🏗️ Architectural Advantages: Based on cloud-native architecture, stable and reliable
  • 🚀 Development efficiency: Automatically generate SDKs to reduce repetitive work
  • 🛡️ Data Security: Built-in validation and access control mechanisms
  • 🎛️ Management Convenience: Visual management interface to reduce operational costs
  • 🤖 Intelligent Analysis: AI-driven data insights
  • 🔧 Flexible Expansion: Supports raw queries and custom logic.

Start your data model journey now! Check out the Quick Start tutorial