Blood and Tears Summary! From Permission Errors to Cross-Platform Compatibility: These Pitfalls You MUST Avoid!
zhongcx

zhongcx @zhongcx

About: The best time to plant a tree was 10 years ago, the second-best time is now.

Joined:
Mar 6, 2025

Blood and Tears Summary! From Permission Errors to Cross-Platform Compatibility: These Pitfalls You MUST Avoid!

Publish Date: May 11
0 0

☁️ Cloud Database Practical Guide

  1. Beginner Zone: The "Excel Worldview" of Cloud Databases Official Documentation Portal

👉 One Sentence to Master It All:
Treat cloud databases as Excel workbooks in the cloud!

Image description

📂 Storage Zone = Excel Sheet (e.g., UserDB, OrderDB)
📑 Object Type = Sheet headers (defining field rules)
📝 Data = Cell contents (Zhang San's age, Li Si's order)
Quick Start Guide:

Log in to AGC Platform → Left menu 【My Projects】
Enter【Cloud Database】→ Right-side trio (Storage Zone/Object Types/Data)
Create structures visually (refer to config guide)

  1. Tablet Developers Alert! Hidden Bugs in Official Demos Painful Lesson: Official demos default to phone-only! Tablets will show blank screens!

Image description

Emergency Fix:

Locate src/main/module.json5
Modify deviceTypes:

// Wrong: Phone-only  
"deviceTypes": ["phone"]  
// Correct: Support both  
"deviceTypes": ["phone", "tablet"]  // Don’t forget the comma!  

Enter fullscreen mode Exit fullscreen mode

Critical! Run Build → Rebuild Project

  1. Hidden Workflow for Schema Modifications Rule: Cloud schema changes MUST sync locally!

Image description

Workflow:

Export schema as JSON from AGC → Object Types
Rename to schema.json
Save to AppScope/resources/rawfile/schema.json (create dir if missing)
Deadly Detail: Recompile after every schema update!

  1. 403 Permission Error: Ultimate Fix

Image description

When seeing this error:

Failed to upsert...403:205525004  // Translation: You have no permissions!  

Enter fullscreen mode Exit fullscreen mode

Check signature guide for solutions.

  1. Cross-Platform Nuclear Option Make CloudDB work on Android/iOS? Two approaches:

Method 1: SDK Integration (Native Devs)

// Android Example  
AGConnectCloudDB cloudDB = AGConnectCloudDB.getInstance();  
CloudDBZoneConfig config = new CloudDBZoneConfig("YourZone");  
cloudDB.openCloudDBZone(config);  

Enter fullscreen mode Exit fullscreen mode

Method 2: REST API (Cross-Platform)

# Query Example  
curl -X POST "https://your-api-endpoint" \  
-H "Authorization: Bearer <token>" \  
-d '{"query":"SELECT * FROM User"}'  

Enter fullscreen mode Exit fullscreen mode
  1. Read-Only Data? Permission Minefield Classic Fail: Can query but not modify data!

Checklist:

Object Type ACL:
AGC → Object Types → Permissions → Enable "Allow other users to write"
User Whitelist Config
Cloud Function Permissions

  1. Upsert 101: Dual-Purpose Operation Existing primary key → Update New primary key → Insert 📱 Local Database Survival Guide
  2. Debugging God Mode: Visualize Your DB Replace console.log with:
ohpm install @hadss/debug-db  # One command to rule them all  

Enter fullscreen mode Exit fullscreen mode

Usage:

import {DebugDB} from '@hadss/debug-db';  
DebugDB.initialize(context);  // Get console URL  

Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:8080/debug-db to:

Inspect RDB schemas
Edit Preferences/KVStore

  1. CRUD Pitfall Cheatsheet

Image description

  1. Transaction Kung Fu Deadlock Scenario:
// WRONG! Nested transactions  
rdbStore.beginTransaction();  
rdbStore.beginTransaction();  // Throws error!  

Enter fullscreen mode Exit fullscreen mode

Correct Approach:

try {  
  rdbStore.beginTransaction();  
  // Operation 1...  
  // Operation 2...  
  await rdbStore.commit();  
} catch (e) {  
  rdbStore.rollback();  
  throw new Error("Transaction failed: " + e.message);  
}  

Enter fullscreen mode Exit fullscreen mode
  1. Database Upgrade Strategies

Image description

💡 FAQ Nuclear Defense Manual
Three Golden Rules:

Design cloud DB permissions early
Wrap local operations in transactions
Check official FAQs first – save 2 hours!
Like this guide? ❤️ Like | ⭐ Bookmark
Share your pitfalls in comments! Let’s improve this together!

HarmonyOSDev #DatabaseBattle #DevSurvivalGuide

Comments 0 total

    Add comment