Help Center/ Huawei Cloud Astro Zero/ FAQs/ Application Backend Development/ Can I Not Use @useObject to Modify Data Objects When Executing SQL Statements in Huawei Cloud Astro Zero Scripts?
Updated on 2025-08-14 GMT+08:00

Can I Not Use @useObject to Modify Data Objects When Executing SQL Statements in Huawei Cloud Astro Zero Scripts?

Scenario

The method shown in the following figure is used when db.sql().execute() is executed in the script. That is, data objects are dynamically used.

Figure 1 Dynamically using data objects

For example, an error will be reported if you do not use @useObject(['User']) when using db.sql().execute("SELECT * FROM User"). Do not use @useObject(['User']) when using db.dynamicObject("User").

Solution

The dynamicObject method is used when the object table to be operated is unknown. For example, a value is assigned externally in the form of a parameter instead of a specific table name. The db.object method is used when the object table to be operated is determined. Therefore, @useObject needs to be used for declaration, as shown in the following figure.

Figure 2 Using @useObject for declaration