Skip to main content

SDK integration

The new version content management operates on top of the data model and provides convenient operation methods through the data model SDK.

Supports convenient use on web, mini programs, cloud functions, and Node.js server-side.

Initialize the SDK

Refer to Importing and Initializing the Data Model SDK

Data Model Namespace

models

After initializing the SDK, operation methods for data models in the current cloud development environment will be automatically mounted on models.

You can access a model's operation methods via models.<model_name>.

Example:

// const wxCloud = client.init(wx.cloud);
// const models = wxCloud.models;

models.<model_name>.create() // Create a single data record
models.<model_name>.createMany() // Create multiple data records
models.<model_name>.update() // Update a single data record
models.<model_name>.updateMany() // Update multiple data records
models.<model_name>.delete() // Delete a single data record
models.<model_name>.deleteMany() // Delete multiple data records
models.<model_name>.get() // Query a single data record
models.<model_name>.list() // Query multiple data records
models.runSQL() // MySQL-type data models support parameterized database queries and are only available for server-side calls.
models.runSQLRaw() // MySQL-type data models support raw database queries and are only available for server-side calls.

Methods of data models can be used in both cloud functions and mini programs.

  • When running on the mini program client, it defaults to invoking with the identity of the currently logged-in user.
  • When running in cloud functions, it defaults to admin permissions. Support for invoking with the identity of a mini program client user will be added later.

Data Model Operation Methods Reference

For details, refer to Model Query Methods