WeChat Mini Program Development [9]--First Understanding of Mini Program Cloud Development

Series Article Directory

Wechat applet development [1] - first understanding of small program portal
WeChat applet development [2] - small program entry portal
Wechat applet development [3] - project structure overview portal
WeChat applet development [4] -- Configuration detailed portal
WeChat applet development [5] -- wxml detailed portal
WeChat applet development [6] -- wxss detailed portal
WeChat applet development [7] -- js detailed portal
WeChat applet development [ Eight]-- Page Stack and Modular Portal
WeChat Mini Program Development [9]-- First Understanding Mini Program Cloud Development Portal
WeChat Mini Program Development [10]-- Cloud Function/Cloud Database/Cloud Storage Portal



1. Background

  • serverless development

No service, also known as Serverless. Serverless means that the development of applications no longer needs to consider hardware infrastructure such as servers. Applications based on the serverless architecture mainly rely on the background services provided by cloud service providers such as Tencent Cloud. For example, serverless cloud functions, cloud databases, object storage services, and so on. To put it simply, it is equivalent to opening a fruit shop to sell fruits now. In the past, you had to rent the store, install water and electricity, and decorate the facade. Now these are all gone, you can rent a shelf or box that has already done a good job for you in a supermarket that has already set up various facilities. One point, follow your mind anytime, anywhere, very flexible.
insert image description here
Why is serverless development a trend? Because the process of cloud services has evolved from physical machines to IAAS and then to PAAS. IAAS includes basic services such as cloud virtual machines, private networks, network leased lines, load balancing, etc.; PAAS is more abstract, such as cloud databases, network protection, and so on. Based on IAAS and PAAS, cloud service providers have developed more advanced development services such as Serverless. Therefore, serverless development will be a new development trend for developing lightweight applications such as small programs in the future.
insert image description here
To sum up, before developing a small program, at least a front-end and a back-end are required, but after using the small program cloud development, it can be simplified into a front-end and a small program can be completely developed, so that it is convenient and fast to practice at low cost project.

2. Main capabilities

1. Cloud function

A cloud function is a piece of code that runs on the cloud. It does not need to manage the server. It can be written in the development tool, uploaded and deployed with one click to run the back-end code. The unique advantage of cloud functions developed by the cloud lies in the seamless integration with WeChat login authentication. When the applet end calls the cloud function, the incoming parameters of the cloud function will be injected with the openid of the user on the applet end. The developer does not need to verify the correctness of the openid because WeChat has already completed this part of the authentication, and the developer can directly use it. The openid.
insert image description here

2. Cloud database

Cloud Development provides a JSON database. As the name suggests, each record in the database is an object in JSON format. A database can have multiple collections (equivalent to tables in relational data), and a collection can be regarded as a JSON array. Each object in the array is a record, and the format of the record is a JSON object.
In this case, there is no need to consider the storage of the database, and a database similar to NOSQL is directly provided, and the visualization window provides the function of importing data, which is very convenient.

// 1. 获取数据库引用
const db = wx.cloud.database()
// 2. 构造查询语句
// collection 方法获取一个集合的引用
// where 方法传入一个对象,数据库返回集合中字段等于指定值的 JSON 文档。API 也支持高级的查询条件(比如大于、小于、in 等),具体见文档查看支持列表
// get 方法会触发网络请求,往数据库取数据
db.collection('books').where({
    
    
  publishInfo: {
    
    
    country: 'United States'
  }
}).get({
    
    
  success(res) {
    
    
  // 输出 [{ "title": "The Catcher in the Rye", ... }]
    console.log(res)
  }
})

3. Cloud storage

Cloud development provides a file storage space, uploading files to the cloud, and cloud download capabilities with permission management. Developers can use cloud file storage functions through APIs on the applet side and cloud function side.
On the applet side, you can call wx.cloud.uploadFile and wx.cloud.downloadFile respectively to upload and download cloud files.


Summarize

Cloud development is a back-end cloud service provided by Tencent Cloud and the WeChat team for developers, including cloud functions, cloud databases and cloud file storage capabilities.
Cloud development provides developers with complete cloud support, weakens the concept of back-end and operation and maintenance, does not need to build a server, uses the API provided by the platform for core business development, and can achieve rapid launch and iteration. At the same time, this capability is the same as that of developers The cloud services used are compatible with each other and are not mutually exclusive.

Guess you like

Origin blog.csdn.net/u011646838/article/details/130301526