[Applet - Cloud Development] Hands-on with Cloud Development (Database Development)


Following the last time the programmer brother simply developed a photo storage applet, I feel that there are still some minor flaws, that is, there is no way to upload photos to the text description. Since it's mostly text, it's obviously not a good idea to save the text descriptions as files to storage space. Well then, let's work together today on the database that comes with cloud development; it should solve this little flaw of ours.

The database that comes with Cloud Development is a bit different from the usual relational databases that you come across. The database provided by Cloud Development is a JSON database, where each record is a JSON formatted object. A database can have multiple collections (equivalent to data tables in relational data), and a collection can be thought of as a JSON array, where each object in the array is a record, and the records are formatted as JSON objects. To put it simply, each record is a JSON, so you don't have to think about building tables and fields.

Isn't it amazing~ as well advertised as it is, you need to look at the features. We're going to build on the photo storage applet we built last time into the extension step by step below.

Click on Cloud Development, click on "Database" on top of the Cloud Development console and then click on "Add Collection"

Building a collection

Adding a collection here is equivalent to building our library (there has to be somewhere to store the data), and with that we are done with the cloud database. Next we just add the data to this collection via the applet.

Since we have to write data to the collection in the database, then the idea is that the photos are uploaded successfully and then the logs are filled in and then saved to the collection. So we're going to create a new page for writing to the log and saving it.

In front of the new page, we want to upload the page before the transformation, that is, after a successful upload plus a page with a file ID jump (wx.navigateTo) to our new record page, the following figure.

Jumping with parameters

Here I have created a simple new record page, mainly a display of the incoming image and text input box and a submit button, where fileid is the incoming file ID. The wxml code is as follows:

front page

Key point:Because we want to receive the file ID value returned after a successful upload, we have to add a receive function to onload. As shown below.

Incoming parameters

Next, let's see how to operate on the cloud database, The first step is definitely to connect to our cloud database can be done viaconst db = wx.cloud.database() come to a connection, Then it writes data to the corresponding data setdb.collection(' The data set says').add()。 The code is as follows:

Code Snippets

Everything is ready for commissioning. When we can see the JSON record we have written in the database in the cloud development controller, so that the data is successfully written to the cloud database.

Write data successful

-END-

Note: This article has been first published in [WeChat Open+] in the [small app community]

For more technical articles you can scan the QR code below to join WeChat Open+


Recommended>>
1、jdk7AbstractQueuedSynchronizer AQS Application Analysis
2、BZOJ3004 Chandelier Conclusion Toxicoma
3、Does React still work without middleware
4、Understanding of 30 Good Lessons for Improving the Efficiency of Web Program Execution
5、Dry Goods ElasticSearch relevance scoring mechanism

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号