cloudbase.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // utils/cloudbase.js
  2. // import { init } from '@cloudbase/wx-cloud-client-sdk'
  3. // wx.cloud.init({
  4. // // env: 'cloud1-6g98iw7i28b01747',
  5. // env: 'honghgaier-5guiffgcf17a2eea',
  6. // traceUser: true
  7. // })
  8. // const client = init(wx.cloud)
  9. // const db = client.database()
  10. // const models = client.models
  11. // const _ = db.command // ✅ 添加这行,导出查询操作符
  12. // export { db, models, _ }
  13. // import { init } from '@cloudbase/wx-cloud-client-sdk'
  14. // // 初始化小程序 SDK
  15. // wx.cloud.init({
  16. // env: 'honghgaier-5guiffgcf17a2eea',
  17. // traceUser: true
  18. // })
  19. // const client = init(wx.cloud)
  20. // const db = client.database()
  21. // const models = client.models
  22. // const _ = db.command
  23. // export { db, models, _ }
  24. // utils/cloudbase.js
  25. import { init } from '@cloudbase/wx-cloud-client-sdk'
  26. let clientInstance = null
  27. export async function getClient() {
  28. if (!clientInstance) {
  29. const cloud = new wx.cloud.Cloud({
  30. resourceAppid: 'wx1ee76fb4846f8901',
  31. resourceEnv: 'honghgaier-5guiffgcf17a2eea',
  32. })
  33. await cloud.init()
  34. clientInstance = init(cloud)
  35. }
  36. return clientInstance
  37. }
  38. export async function getDB() {
  39. const client = await getClient()
  40. return client.database()
  41. }
  42. export async function getModels() {
  43. const client = await getClient()
  44. return client.models
  45. }
  46. export async function getCommand() {
  47. const db = await getDB()
  48. return db.command
  49. }
  50. export async function getTempFileURLs(fileIDs) {
  51. const client = await getClient()
  52. return client.getTempFileURL({ fileList: fileIDs }).then(res => res.fileList)
  53. }
  54. // export async function db() {
  55. // const db = await getDB()
  56. // return { db }
  57. // }
  58. // export async function models() {
  59. // const models = await getModels()
  60. // return { models }
  61. // }
  62. // export async function _() {
  63. // const _ = await getCommand()
  64. // return { _, }
  65. // }