新聞中心
Database
云開發(fā) SDK 數(shù)據(jù)庫實例

創(chuàng)新互聯(lián)主要企業(yè)基礎官網(wǎng)建設,電商平臺建設,移動手機平臺,小程序制作等一系列專為中小企業(yè)按需開發(fā)網(wǎng)站產(chǎn)品體系;應對中小企業(yè)在互聯(lián)網(wǎng)運營的各種問題,為中小企業(yè)在互聯(lián)網(wǎng)的運營中保駕護航。
屬性
Command command
數(shù)據(jù)庫操作符
Geo Geo
數(shù)據(jù)庫地理位置結構
方法
Database.collection(name: string): Collection
獲取集合的引用。方法接受一個 name 參數(shù),指定需引用的集合名稱。
Database.createCollection(collectionName: string): Promise
創(chuàng)建集合,如果集合已經(jīng)存在會創(chuàng)建失敗
Database.serverDate(options: Object): ServerDate
構造一個服務端時間的引用??捎糜诓樵儣l件、更新字段值或新增記錄時的字段值。
Database.runTransaction(callback: function, times: number): Promise
發(fā)起事務。僅可在云函數(shù)中使用。
Database.startTransaction(): Promise
開始事務,另一個同樣可以使用的發(fā)起事務的 API 是 runTransaction。僅可在云函數(shù)中使用。
小程序端示例
以下調用獲取默認環(huán)境的數(shù)據(jù)庫的引用:
const db = wx.cloud.database()
假設有一個環(huán)境名為 test-123,用做測試環(huán)境,那么可以如下獲取測試環(huán)境數(shù)據(jù)庫:
const testDB = wx.cloud.database({
env: 'test-123'
})
云函數(shù)端示例
以下調用獲取和云函數(shù)當前所在環(huán)境相同的數(shù)據(jù)庫的引用:
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
假設有一個環(huán)境名為 test,用做測試環(huán)境,那么可以如下獲取測試環(huán)境數(shù)據(jù)庫:
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const testDB = cloud.database({
env: 'test'
})
也可以通過 init 傳入默認環(huán)境的方式使得獲取數(shù)據(jù)庫時默認是默認環(huán)境數(shù)據(jù)庫:
const cloud = require('wx-server-sdk')
cloud.init({
env: 'test'
})
const testDB = cloud.database() 分享名稱:創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫database·索引
標題路徑:http://m.5511xx.com/article/ccdhpcd.html


咨詢
建站咨詢
