@cloudbase/js-sdk 3.1.4 → 3.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/index.d.ts +492 -75
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/auth.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/oauth.js +1 -1
- package/package.json +15 -15
package/index.d.ts
CHANGED
|
@@ -525,7 +525,7 @@ declare namespace cloudbase.app {
|
|
|
525
525
|
/**
|
|
526
526
|
* 获取数据库实例
|
|
527
527
|
*
|
|
528
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
|
|
528
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
|
|
529
529
|
*
|
|
530
530
|
* @example
|
|
531
531
|
* ```javascript
|
|
@@ -537,7 +537,7 @@ declare namespace cloudbase.app {
|
|
|
537
537
|
*
|
|
538
538
|
* @return 数据库实例
|
|
539
539
|
*/
|
|
540
|
-
database(dbConfig?:
|
|
540
|
+
database(dbConfig?: cloudbase.database.IDbConfig): cloudbase.database.App
|
|
541
541
|
/**
|
|
542
542
|
* 调用扩展能力插件功能
|
|
543
543
|
*
|
|
@@ -1444,7 +1444,7 @@ declare namespace cloudbase.database {
|
|
|
1444
1444
|
/**
|
|
1445
1445
|
* 关闭实时推送
|
|
1446
1446
|
*
|
|
1447
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#shu-ju-ku-shi-shi-tui-song}
|
|
1447
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#shu-ju-ku-shi-shi-tui-song}
|
|
1448
1448
|
*
|
|
1449
1449
|
* @example
|
|
1450
1450
|
* // 启动监听
|
|
@@ -1489,7 +1489,7 @@ declare namespace cloudbase.database {
|
|
|
1489
1489
|
/**
|
|
1490
1490
|
* 开启实时推送
|
|
1491
1491
|
*
|
|
1492
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E6%97%B6%E6%8E%A8%E9%80%81}
|
|
1492
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E6%97%B6%E6%8E%A8%E9%80%81}
|
|
1493
1493
|
*
|
|
1494
1494
|
* @example
|
|
1495
1495
|
* const ref = db
|
|
@@ -1516,21 +1516,44 @@ declare namespace cloudbase.database {
|
|
|
1516
1516
|
*/
|
|
1517
1517
|
interface ICollection extends IQuery {
|
|
1518
1518
|
/**
|
|
1519
|
-
*
|
|
1519
|
+
* 向集合中添加一条新记录
|
|
1520
1520
|
*
|
|
1521
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#add}
|
|
1521
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#add}
|
|
1522
1522
|
*
|
|
1523
|
-
* @
|
|
1523
|
+
* @example
|
|
1524
|
+
* const result = await db.collection('todos').add({
|
|
1525
|
+
* title: '学习 CloudBase',
|
|
1526
|
+
* completed: false
|
|
1527
|
+
* })
|
|
1528
|
+
* console.log('新增成功,文档 ID:', result.id)
|
|
1529
|
+
*
|
|
1530
|
+
* @param data 要新增的数据对象,支持嵌套对象、数组、地理位置等数据类型
|
|
1531
|
+
*
|
|
1532
|
+
* @return Promise<AddRes> 包含新增文档的 id 和 requestId
|
|
1524
1533
|
*/
|
|
1525
|
-
add(data: Object): Promise<
|
|
1534
|
+
add(data: Object): Promise<AddRes>
|
|
1526
1535
|
/**
|
|
1527
1536
|
* 获取一条文档的引用
|
|
1528
1537
|
*
|
|
1529
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#record--document}
|
|
1538
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#record--document}
|
|
1530
1539
|
*
|
|
1531
1540
|
* @param id 文档ID
|
|
1532
1541
|
*/
|
|
1533
|
-
doc(id: string): IDocument
|
|
1542
|
+
doc(id: string | number): IDocument
|
|
1543
|
+
/**
|
|
1544
|
+
* 获取聚合操作对象
|
|
1545
|
+
*
|
|
1546
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#aggregate}
|
|
1547
|
+
*
|
|
1548
|
+
* @example
|
|
1549
|
+
* const result = await db.collection('todos')
|
|
1550
|
+
* .aggregate()
|
|
1551
|
+
* .group({ _id: '$priority', count: { $sum: 1 } })
|
|
1552
|
+
* .end()
|
|
1553
|
+
*
|
|
1554
|
+
* @return 聚合操作对象,可链式调用各种聚合阶段方法
|
|
1555
|
+
*/
|
|
1556
|
+
aggregate(): IAggregate
|
|
1534
1557
|
}
|
|
1535
1558
|
/**
|
|
1536
1559
|
* command types
|
|
@@ -1550,7 +1573,7 @@ declare namespace cloudbase.database {
|
|
|
1550
1573
|
/**
|
|
1551
1574
|
* 表示字段等于某个值
|
|
1552
1575
|
*
|
|
1553
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#eq}
|
|
1576
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#eq}
|
|
1554
1577
|
*
|
|
1555
1578
|
* @example
|
|
1556
1579
|
* const _ = db.command;
|
|
@@ -1565,7 +1588,7 @@ declare namespace cloudbase.database {
|
|
|
1565
1588
|
/**
|
|
1566
1589
|
* 表示字段不等于某个值
|
|
1567
1590
|
*
|
|
1568
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
|
|
1591
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
|
|
1569
1592
|
*
|
|
1570
1593
|
* @example
|
|
1571
1594
|
* const _ = db.command;
|
|
@@ -1580,7 +1603,7 @@ declare namespace cloudbase.database {
|
|
|
1580
1603
|
/**
|
|
1581
1604
|
* 字段大于指定值
|
|
1582
1605
|
*
|
|
1583
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#gt}
|
|
1606
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#gt}
|
|
1584
1607
|
*
|
|
1585
1608
|
* @example
|
|
1586
1609
|
* const _ = db.command;
|
|
@@ -1595,7 +1618,7 @@ declare namespace cloudbase.database {
|
|
|
1595
1618
|
/**
|
|
1596
1619
|
* 字段大于或等于指定值
|
|
1597
1620
|
*
|
|
1598
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
|
|
1621
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
|
|
1599
1622
|
*
|
|
1600
1623
|
* @example
|
|
1601
1624
|
* const _ = db.command;
|
|
@@ -1610,7 +1633,7 @@ declare namespace cloudbase.database {
|
|
|
1610
1633
|
/**
|
|
1611
1634
|
* 字段小于指定值
|
|
1612
1635
|
*
|
|
1613
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#lt}
|
|
1636
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lt}
|
|
1614
1637
|
*
|
|
1615
1638
|
* @example
|
|
1616
1639
|
* const _ = db.command;
|
|
@@ -1625,7 +1648,7 @@ declare namespace cloudbase.database {
|
|
|
1625
1648
|
/**
|
|
1626
1649
|
* 字段小于或等于指定值
|
|
1627
1650
|
*
|
|
1628
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#lte}
|
|
1651
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lte}
|
|
1629
1652
|
*
|
|
1630
1653
|
* @example
|
|
1631
1654
|
* const _ = db.command;
|
|
@@ -1640,7 +1663,7 @@ declare namespace cloudbase.database {
|
|
|
1640
1663
|
/**
|
|
1641
1664
|
* 字段值在给定的数组中
|
|
1642
1665
|
*
|
|
1643
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#in}
|
|
1666
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#in}
|
|
1644
1667
|
*
|
|
1645
1668
|
* @example
|
|
1646
1669
|
* const _ = db.command;
|
|
@@ -1655,7 +1678,7 @@ declare namespace cloudbase.database {
|
|
|
1655
1678
|
/**
|
|
1656
1679
|
* 字段值不在给定的数组中
|
|
1657
1680
|
*
|
|
1658
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#nin}
|
|
1681
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#nin}
|
|
1659
1682
|
*
|
|
1660
1683
|
* @example
|
|
1661
1684
|
* const _ = db.command;
|
|
@@ -1670,7 +1693,7 @@ declare namespace cloudbase.database {
|
|
|
1670
1693
|
/**
|
|
1671
1694
|
* 表示需同时满足指定的两个或以上的条件
|
|
1672
1695
|
*
|
|
1673
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#and}
|
|
1696
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#and}
|
|
1674
1697
|
*
|
|
1675
1698
|
* @example
|
|
1676
1699
|
* const _ = db.command;
|
|
@@ -1685,7 +1708,7 @@ declare namespace cloudbase.database {
|
|
|
1685
1708
|
/**
|
|
1686
1709
|
* 表示需满足所有指定条件中的至少一个
|
|
1687
1710
|
*
|
|
1688
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#or}
|
|
1711
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#or}
|
|
1689
1712
|
*
|
|
1690
1713
|
* @example
|
|
1691
1714
|
* const _ = db.command;
|
|
@@ -1700,7 +1723,7 @@ declare namespace cloudbase.database {
|
|
|
1700
1723
|
/**
|
|
1701
1724
|
* 用于设定字段等于指定值
|
|
1702
1725
|
*
|
|
1703
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#set}
|
|
1726
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#set}
|
|
1704
1727
|
*
|
|
1705
1728
|
* @example
|
|
1706
1729
|
* const _ = db.command;
|
|
@@ -1721,7 +1744,7 @@ declare namespace cloudbase.database {
|
|
|
1721
1744
|
/**
|
|
1722
1745
|
* 用于指示字段自增某个值
|
|
1723
1746
|
*
|
|
1724
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#inc}
|
|
1747
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#inc}
|
|
1725
1748
|
*
|
|
1726
1749
|
* @example
|
|
1727
1750
|
* const _ = db.command;
|
|
@@ -1740,7 +1763,7 @@ declare namespace cloudbase.database {
|
|
|
1740
1763
|
/**
|
|
1741
1764
|
* 用于指示字段自乘某个值
|
|
1742
1765
|
*
|
|
1743
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#mul}
|
|
1766
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#mul}
|
|
1744
1767
|
*
|
|
1745
1768
|
* @example
|
|
1746
1769
|
* const _ = db.command;
|
|
@@ -1759,7 +1782,7 @@ declare namespace cloudbase.database {
|
|
|
1759
1782
|
/**
|
|
1760
1783
|
* 用于表示删除某个字段
|
|
1761
1784
|
*
|
|
1762
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#remove}
|
|
1785
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove}
|
|
1763
1786
|
*
|
|
1764
1787
|
* @example
|
|
1765
1788
|
* const _ = db.command;
|
|
@@ -1774,7 +1797,7 @@ declare namespace cloudbase.database {
|
|
|
1774
1797
|
/**
|
|
1775
1798
|
* 向数组尾部追加元素
|
|
1776
1799
|
*
|
|
1777
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#push}
|
|
1800
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#push}
|
|
1778
1801
|
*
|
|
1779
1802
|
* @example
|
|
1780
1803
|
* const _ = db.command;
|
|
@@ -1790,7 +1813,7 @@ declare namespace cloudbase.database {
|
|
|
1790
1813
|
/**
|
|
1791
1814
|
* 删除数组尾部元素
|
|
1792
1815
|
*
|
|
1793
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#pop}
|
|
1816
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#pop}
|
|
1794
1817
|
*
|
|
1795
1818
|
* @example
|
|
1796
1819
|
* const _ = db.command;
|
|
@@ -1805,7 +1828,7 @@ declare namespace cloudbase.database {
|
|
|
1805
1828
|
/**
|
|
1806
1829
|
* 向数组头部添加元素
|
|
1807
1830
|
*
|
|
1808
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#unshift}
|
|
1831
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#unshift}
|
|
1809
1832
|
*
|
|
1810
1833
|
* @example
|
|
1811
1834
|
* const _ = db.command;
|
|
@@ -1821,7 +1844,7 @@ declare namespace cloudbase.database {
|
|
|
1821
1844
|
/**
|
|
1822
1845
|
* 删除数组头部元素
|
|
1823
1846
|
*
|
|
1824
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#shift}
|
|
1847
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#shift}
|
|
1825
1848
|
*
|
|
1826
1849
|
* @example
|
|
1827
1850
|
* const _ = db.command;
|
|
@@ -1833,10 +1856,148 @@ declare namespace cloudbase.database {
|
|
|
1833
1856
|
*
|
|
1834
1857
|
*/
|
|
1835
1858
|
shift(): any
|
|
1859
|
+
/**
|
|
1860
|
+
* 条件取反
|
|
1861
|
+
*
|
|
1862
|
+
* @example
|
|
1863
|
+
* const _ = db.command;
|
|
1864
|
+
* db.collection('users').where({
|
|
1865
|
+
* status: _.not(_.eq('deleted'))
|
|
1866
|
+
* })
|
|
1867
|
+
*
|
|
1868
|
+
* @param condition 查询条件
|
|
1869
|
+
*/
|
|
1870
|
+
not(condition: any): any
|
|
1871
|
+
/**
|
|
1872
|
+
* 都不满足指定的条件
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* const _ = db.command;
|
|
1876
|
+
* db.collection('users').where(
|
|
1877
|
+
* _.nor([{ status: 'banned' }, { status: 'deleted' }])
|
|
1878
|
+
* )
|
|
1879
|
+
*
|
|
1880
|
+
* @param conditions 条件数组
|
|
1881
|
+
*/
|
|
1882
|
+
nor(conditions: any[]): any
|
|
1883
|
+
/**
|
|
1884
|
+
* 判断字段是否存在
|
|
1885
|
+
*
|
|
1886
|
+
* @example
|
|
1887
|
+
* const _ = db.command;
|
|
1888
|
+
* db.collection('users').where({
|
|
1889
|
+
* avatar: _.exists(true)
|
|
1890
|
+
* })
|
|
1891
|
+
*
|
|
1892
|
+
* @param val true 表示字段存在,false 表示不存在
|
|
1893
|
+
*/
|
|
1894
|
+
exists(val: boolean): any
|
|
1895
|
+
/**
|
|
1896
|
+
* 取模运算
|
|
1897
|
+
*
|
|
1898
|
+
* @example
|
|
1899
|
+
* const _ = db.command;
|
|
1900
|
+
* db.collection('users').where({
|
|
1901
|
+
* age: _.mod([2, 0])
|
|
1902
|
+
* })
|
|
1903
|
+
*
|
|
1904
|
+
* @param val [除数, 余数]
|
|
1905
|
+
*/
|
|
1906
|
+
mod(val: [number, number]): any
|
|
1907
|
+
/**
|
|
1908
|
+
* 数组包含所有指定元素
|
|
1909
|
+
*
|
|
1910
|
+
* @example
|
|
1911
|
+
* const _ = db.command;
|
|
1912
|
+
* db.collection('articles').where({
|
|
1913
|
+
* tags: _.all(['javascript', 'nodejs'])
|
|
1914
|
+
* })
|
|
1915
|
+
*
|
|
1916
|
+
* @param list 必须包含的元素数组
|
|
1917
|
+
*/
|
|
1918
|
+
all(list: any[]): any
|
|
1919
|
+
/**
|
|
1920
|
+
* 数组元素匹配
|
|
1921
|
+
*
|
|
1922
|
+
* @example
|
|
1923
|
+
* const _ = db.command;
|
|
1924
|
+
* db.collection('orders').where({
|
|
1925
|
+
* items: _.elemMatch({ price: _.gt(100) })
|
|
1926
|
+
* })
|
|
1927
|
+
*
|
|
1928
|
+
* @param condition 匹配条件对象
|
|
1929
|
+
*/
|
|
1930
|
+
elemMatch(condition: Object): any
|
|
1931
|
+
/**
|
|
1932
|
+
* 数组长度匹配
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* const _ = db.command;
|
|
1936
|
+
* db.collection('articles').where({
|
|
1937
|
+
* tags: _.size(3)
|
|
1938
|
+
* })
|
|
1939
|
+
*
|
|
1940
|
+
* @param size 数组长度
|
|
1941
|
+
*/
|
|
1942
|
+
size(size: number): any
|
|
1943
|
+
/**
|
|
1944
|
+
* 取最小值更新
|
|
1945
|
+
*
|
|
1946
|
+
* @param val 比较值
|
|
1947
|
+
*/
|
|
1948
|
+
min(val: number): any
|
|
1949
|
+
/**
|
|
1950
|
+
* 取最大值更新
|
|
1951
|
+
*
|
|
1952
|
+
* @param val 比较值
|
|
1953
|
+
*/
|
|
1954
|
+
max(val: number): any
|
|
1955
|
+
/**
|
|
1956
|
+
* 重命名字段
|
|
1957
|
+
*
|
|
1958
|
+
* @param newFieldName 新字段名
|
|
1959
|
+
*/
|
|
1960
|
+
rename(newFieldName: string): any
|
|
1961
|
+
/**
|
|
1962
|
+
* 位运算
|
|
1963
|
+
*
|
|
1964
|
+
* @param options 位运算选项,如 { and: 5 }
|
|
1965
|
+
*/
|
|
1966
|
+
bit(options: Object): any
|
|
1967
|
+
/**
|
|
1968
|
+
* 删除数组中匹配的元素
|
|
1969
|
+
*
|
|
1970
|
+
* @example
|
|
1971
|
+
* const _ = db.command;
|
|
1972
|
+
* db.collection('articles').doc('id').update({
|
|
1973
|
+
* tags: _.pull('要删除的标签')
|
|
1974
|
+
* })
|
|
1975
|
+
*
|
|
1976
|
+
* @param val 要删除的元素或匹配条件
|
|
1977
|
+
*/
|
|
1978
|
+
pull(val: any): any
|
|
1979
|
+
/**
|
|
1980
|
+
* 删除数组中所有匹配的元素
|
|
1981
|
+
*
|
|
1982
|
+
* @param list 要删除的元素数组
|
|
1983
|
+
*/
|
|
1984
|
+
pullAll(list: any[]): any
|
|
1985
|
+
/**
|
|
1986
|
+
* 向数组添加不重复的元素
|
|
1987
|
+
*
|
|
1988
|
+
* @example
|
|
1989
|
+
* const _ = db.command;
|
|
1990
|
+
* db.collection('articles').doc('id').update({
|
|
1991
|
+
* tags: _.addToSet('唯一标签')
|
|
1992
|
+
* })
|
|
1993
|
+
*
|
|
1994
|
+
* @param val 要添加的元素
|
|
1995
|
+
*/
|
|
1996
|
+
addToSet(val: any): any
|
|
1836
1997
|
/**
|
|
1837
1998
|
* 按从近到远的顺序,找出字段值在给定点的附近的文档
|
|
1838
1999
|
*
|
|
1839
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geonear}
|
|
2000
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geonear}
|
|
1840
2001
|
*
|
|
1841
2002
|
* @example
|
|
1842
2003
|
* const _ = db.command;
|
|
@@ -1857,7 +2018,7 @@ declare namespace cloudbase.database {
|
|
|
1857
2018
|
/**
|
|
1858
2019
|
* 找出字段值在指定 Polygon / MultiPolygon 内的文档,无排序
|
|
1859
2020
|
*
|
|
1860
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geowithin}
|
|
2021
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geowithin}
|
|
1861
2022
|
*
|
|
1862
2023
|
* @example
|
|
1863
2024
|
* const _ = db.command;
|
|
@@ -1876,7 +2037,7 @@ declare namespace cloudbase.database {
|
|
|
1876
2037
|
/**
|
|
1877
2038
|
* 找出字段值和给定的地理位置图形相交的文档
|
|
1878
2039
|
*
|
|
1879
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geointersects}
|
|
2040
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geointersects}
|
|
1880
2041
|
*
|
|
1881
2042
|
* @example
|
|
1882
2043
|
* const _ = db.command;
|
|
@@ -1896,9 +2057,9 @@ declare namespace cloudbase.database {
|
|
|
1896
2057
|
*/
|
|
1897
2058
|
interface IDocument extends IWatchable {
|
|
1898
2059
|
/**
|
|
1899
|
-
*
|
|
2060
|
+
* 设置文档数据,如果文档不存在则创建新文档
|
|
1900
2061
|
*
|
|
1901
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
|
|
2062
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
|
|
1902
2063
|
*
|
|
1903
2064
|
* @example
|
|
1904
2065
|
* collection
|
|
@@ -1906,55 +2067,65 @@ declare namespace cloudbase.database {
|
|
|
1906
2067
|
* .set({name:'cloudbase'})
|
|
1907
2068
|
* .then(res=>{})
|
|
1908
2069
|
*
|
|
1909
|
-
* @param data
|
|
2070
|
+
* @param data 要设置的数据对象,将完全替换原有文档内容
|
|
1910
2071
|
*
|
|
1911
|
-
* @return Promise
|
|
2072
|
+
* @return Promise<SetRes> 包含 updated 或 upsertedId
|
|
1912
2073
|
*/
|
|
1913
2074
|
set(data: Object): Promise<SetRes>
|
|
1914
2075
|
/**
|
|
1915
|
-
*
|
|
2076
|
+
* 获取文档数据
|
|
1916
2077
|
*
|
|
1917
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#get}
|
|
2078
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#get}
|
|
1918
2079
|
*
|
|
1919
2080
|
* @example
|
|
1920
2081
|
* collection
|
|
1921
2082
|
* .doc('docId')
|
|
1922
2083
|
* .get()
|
|
1923
|
-
* .then(res=>{})
|
|
2084
|
+
* .then(res=>{ console.log(res.data) })
|
|
1924
2085
|
*
|
|
1925
|
-
* @return Promise
|
|
2086
|
+
* @return Promise<GetRes> 包含 data 数组和 requestId
|
|
1926
2087
|
*/
|
|
1927
2088
|
get(): Promise<GetRes>
|
|
1928
2089
|
/**
|
|
1929
|
-
*
|
|
2090
|
+
* 更新文档数据,如果文档不存在则不做任何操作
|
|
1930
2091
|
*
|
|
1931
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#update--set}
|
|
2092
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#update--set}
|
|
1932
2093
|
*
|
|
1933
2094
|
* @example
|
|
1934
2095
|
* collection
|
|
1935
2096
|
* .doc('docId')
|
|
1936
|
-
* .update({
|
|
1937
|
-
* .then(res=>{})
|
|
2097
|
+
* .update({completed: true})
|
|
2098
|
+
* .then(res=>{ console.log(res.updated) })
|
|
1938
2099
|
*
|
|
1939
|
-
* @param data
|
|
2100
|
+
* @param data 要更新的数据对象,支持操作符
|
|
1940
2101
|
*
|
|
1941
|
-
* @return Promise
|
|
2102
|
+
* @return Promise<UpdateRes> 包含 updated 字段
|
|
1942
2103
|
*/
|
|
1943
|
-
update(data: Object): Promise<
|
|
2104
|
+
update(data: Object): Promise<UpdateRes>
|
|
1944
2105
|
/**
|
|
1945
2106
|
* 删除一条文档
|
|
1946
2107
|
*
|
|
1947
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#remove-2}
|
|
2108
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#remove-2}
|
|
1948
2109
|
*
|
|
1949
2110
|
* @example
|
|
1950
2111
|
* collection
|
|
1951
2112
|
* .doc('docId')
|
|
1952
2113
|
* .remove()
|
|
1953
|
-
* .then(res=>{})
|
|
2114
|
+
* .then(res=>{ console.log(res.deleted) })
|
|
1954
2115
|
*
|
|
1955
|
-
* @return Promise
|
|
2116
|
+
* @return Promise<RemoveRes> 包含 deleted 字段
|
|
1956
2117
|
*/
|
|
1957
|
-
remove(): Promise<
|
|
2118
|
+
remove(): Promise<RemoveRes>
|
|
2119
|
+
/**
|
|
2120
|
+
* 指定要返回的字段
|
|
2121
|
+
*
|
|
2122
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
|
|
2123
|
+
*
|
|
2124
|
+
* @param projection 字段投影对象,true 表示返回,false 表示不返回
|
|
2125
|
+
*
|
|
2126
|
+
* @return 文档引用,可继续链式调用 get()
|
|
2127
|
+
*/
|
|
2128
|
+
field(projection: Object): IDocument
|
|
1958
2129
|
}
|
|
1959
2130
|
/**
|
|
1960
2131
|
* query types
|
|
@@ -1963,7 +2134,7 @@ declare namespace cloudbase.database {
|
|
|
1963
2134
|
code?: string
|
|
1964
2135
|
message?: string
|
|
1965
2136
|
updated?: number
|
|
1966
|
-
upsertedId?:
|
|
2137
|
+
upsertedId?: string
|
|
1967
2138
|
requestId: string
|
|
1968
2139
|
}
|
|
1969
2140
|
interface GetRes {
|
|
@@ -1976,11 +2147,181 @@ declare namespace cloudbase.database {
|
|
|
1976
2147
|
interface UpdateRes {
|
|
1977
2148
|
requestId: string
|
|
1978
2149
|
updated?: number
|
|
1979
|
-
|
|
2150
|
+
upsertedId?: string
|
|
1980
2151
|
code?: string
|
|
1981
2152
|
message?: string
|
|
1982
2153
|
}
|
|
1983
2154
|
|
|
2155
|
+
interface AddRes {
|
|
2156
|
+
id: string
|
|
2157
|
+
requestId: string
|
|
2158
|
+
code?: string
|
|
2159
|
+
message?: string
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
interface CountRes {
|
|
2163
|
+
total: number
|
|
2164
|
+
requestId: string
|
|
2165
|
+
code?: string
|
|
2166
|
+
message?: string
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
interface RemoveRes {
|
|
2170
|
+
deleted: number
|
|
2171
|
+
requestId: string
|
|
2172
|
+
code?: string
|
|
2173
|
+
message?: string
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
interface CreateCollectionRes {
|
|
2177
|
+
data: string
|
|
2178
|
+
requestId: string
|
|
2179
|
+
code?: string
|
|
2180
|
+
message?: string
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
interface IRunCommandsReq {
|
|
2184
|
+
/** 命令对象数组 */
|
|
2185
|
+
commands: Object[]
|
|
2186
|
+
/** 事务 ID(可选) */
|
|
2187
|
+
transactionId?: string
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
interface IRunCommandsResult {
|
|
2191
|
+
requestId: string
|
|
2192
|
+
/** 命令执行结果数组 */
|
|
2193
|
+
list: Object[][]
|
|
2194
|
+
code?: string
|
|
2195
|
+
message?: string
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
/**
|
|
2199
|
+
* 数据库配置
|
|
2200
|
+
*/
|
|
2201
|
+
interface IDbConfig {
|
|
2202
|
+
/** 实例 ID(可选),不填则使用默认实例 */
|
|
2203
|
+
instance?: string
|
|
2204
|
+
/** 数据库名称(可选),不填则使用默认数据库 */
|
|
2205
|
+
database?: string
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
/**
|
|
2209
|
+
* 聚合操作对象
|
|
2210
|
+
*/
|
|
2211
|
+
interface IAggregate {
|
|
2212
|
+
/**
|
|
2213
|
+
* 添加新字段
|
|
2214
|
+
*/
|
|
2215
|
+
addFields(fieldObj: Object): IAggregate
|
|
2216
|
+
/**
|
|
2217
|
+
* 分桶
|
|
2218
|
+
*/
|
|
2219
|
+
bucket(bucketObj: Object): IAggregate
|
|
2220
|
+
/**
|
|
2221
|
+
* 自动分桶
|
|
2222
|
+
*/
|
|
2223
|
+
bucketAuto(bucketObj: Object): IAggregate
|
|
2224
|
+
/**
|
|
2225
|
+
* 计数
|
|
2226
|
+
*/
|
|
2227
|
+
count(fieldName: string): IAggregate
|
|
2228
|
+
/**
|
|
2229
|
+
* 地理位置附近查询
|
|
2230
|
+
*/
|
|
2231
|
+
geoNear(options: Object): IAggregate
|
|
2232
|
+
/**
|
|
2233
|
+
* 分组统计
|
|
2234
|
+
*
|
|
2235
|
+
* @example
|
|
2236
|
+
* db.collection('todos').aggregate()
|
|
2237
|
+
* .group({ _id: '$priority', count: { $sum: 1 } })
|
|
2238
|
+
* .end()
|
|
2239
|
+
*/
|
|
2240
|
+
group(groupObj: Object): IAggregate
|
|
2241
|
+
/**
|
|
2242
|
+
* 限制结果数量
|
|
2243
|
+
*/
|
|
2244
|
+
limit(limit: number): IAggregate
|
|
2245
|
+
/**
|
|
2246
|
+
* 联表查询
|
|
2247
|
+
*/
|
|
2248
|
+
lookup(lookupObj: Object): IAggregate
|
|
2249
|
+
/**
|
|
2250
|
+
* 条件筛选
|
|
2251
|
+
*/
|
|
2252
|
+
match(matchObj: Object): IAggregate
|
|
2253
|
+
/**
|
|
2254
|
+
* 字段投影
|
|
2255
|
+
*/
|
|
2256
|
+
project(projectObj: Object): IAggregate
|
|
2257
|
+
/**
|
|
2258
|
+
* 替换根文档
|
|
2259
|
+
*/
|
|
2260
|
+
replaceRoot(replaceObj: Object): IAggregate
|
|
2261
|
+
/**
|
|
2262
|
+
* 随机采样
|
|
2263
|
+
*/
|
|
2264
|
+
sample(sampleObj: Object): IAggregate
|
|
2265
|
+
/**
|
|
2266
|
+
* 跳过数量
|
|
2267
|
+
*/
|
|
2268
|
+
skip(skip: number): IAggregate
|
|
2269
|
+
/**
|
|
2270
|
+
* 排序
|
|
2271
|
+
*/
|
|
2272
|
+
sort(sortObj: Object): IAggregate
|
|
2273
|
+
/**
|
|
2274
|
+
* 按数量排序
|
|
2275
|
+
*/
|
|
2276
|
+
sortByCount(fieldName: string): IAggregate
|
|
2277
|
+
/**
|
|
2278
|
+
* 展开数组
|
|
2279
|
+
*/
|
|
2280
|
+
unwind(fieldPath: string | Object): IAggregate
|
|
2281
|
+
/**
|
|
2282
|
+
* 结束聚合管道,返回结果
|
|
2283
|
+
*/
|
|
2284
|
+
end(): Promise<GetRes>
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* 事务对象
|
|
2289
|
+
*/
|
|
2290
|
+
interface ITransaction {
|
|
2291
|
+
/**
|
|
2292
|
+
* 获取事务内的集合引用
|
|
2293
|
+
*/
|
|
2294
|
+
collection(name: string): ITransactionCollection
|
|
2295
|
+
/**
|
|
2296
|
+
* 提交事务
|
|
2297
|
+
*/
|
|
2298
|
+
commit(): Promise<void>
|
|
2299
|
+
/**
|
|
2300
|
+
* 回滚事务
|
|
2301
|
+
*
|
|
2302
|
+
* @param reason 回滚原因
|
|
2303
|
+
*/
|
|
2304
|
+
rollback(reason?: any): Promise<void>
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* 事务内的集合引用
|
|
2309
|
+
*/
|
|
2310
|
+
interface ITransactionCollection {
|
|
2311
|
+
doc(id: string): ITransactionDocument
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* 事务内的文档引用
|
|
2316
|
+
*/
|
|
2317
|
+
interface ITransactionDocument {
|
|
2318
|
+
get(): Promise<GetRes>
|
|
2319
|
+
create(data: Object): Promise<any>
|
|
2320
|
+
set(data: Object): Promise<SetRes>
|
|
2321
|
+
update(data: Object): Promise<UpdateRes>
|
|
2322
|
+
remove(): Promise<RemoveRes>
|
|
2323
|
+
}
|
|
2324
|
+
|
|
1984
2325
|
interface QueryOrder {
|
|
1985
2326
|
field?: string
|
|
1986
2327
|
direction?: 'asc' | 'desc'
|
|
@@ -1998,7 +2339,7 @@ declare namespace cloudbase.database {
|
|
|
1998
2339
|
/**
|
|
1999
2340
|
* 获取数据库查询结果
|
|
2000
2341
|
*
|
|
2001
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#get}
|
|
2342
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#get}
|
|
2002
2343
|
*
|
|
2003
2344
|
* @example
|
|
2004
2345
|
* collection
|
|
@@ -2014,7 +2355,7 @@ declare namespace cloudbase.database {
|
|
|
2014
2355
|
/**
|
|
2015
2356
|
* 更新数据库文档
|
|
2016
2357
|
*
|
|
2017
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
|
|
2358
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
|
|
2018
2359
|
*
|
|
2019
2360
|
* @example
|
|
2020
2361
|
* collection
|
|
@@ -2032,7 +2373,7 @@ declare namespace cloudbase.database {
|
|
|
2032
2373
|
/**
|
|
2033
2374
|
* 获取数据库查询结果的数目
|
|
2034
2375
|
*
|
|
2035
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#count}
|
|
2376
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#count}
|
|
2036
2377
|
*
|
|
2037
2378
|
* @example
|
|
2038
2379
|
* collection
|
|
@@ -2042,13 +2383,13 @@ declare namespace cloudbase.database {
|
|
|
2042
2383
|
* .count()
|
|
2043
2384
|
* .then(res=>{})
|
|
2044
2385
|
*
|
|
2045
|
-
* @return Promise
|
|
2386
|
+
* @return Promise<CountRes> 包含 total 字段
|
|
2046
2387
|
*/
|
|
2047
|
-
count(): Promise<
|
|
2388
|
+
count(): Promise<CountRes>
|
|
2048
2389
|
/**
|
|
2049
2390
|
* 设置过滤条件
|
|
2050
2391
|
*
|
|
2051
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#where}
|
|
2392
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#where}
|
|
2052
2393
|
*
|
|
2053
2394
|
* @example
|
|
2054
2395
|
* collection
|
|
@@ -2063,7 +2404,7 @@ declare namespace cloudbase.database {
|
|
|
2063
2404
|
/**
|
|
2064
2405
|
* 指定查询结果集数量上限
|
|
2065
2406
|
*
|
|
2066
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#limit}
|
|
2407
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#limit}
|
|
2067
2408
|
*
|
|
2068
2409
|
* @example
|
|
2069
2410
|
* collection
|
|
@@ -2078,7 +2419,7 @@ declare namespace cloudbase.database {
|
|
|
2078
2419
|
/**
|
|
2079
2420
|
* 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
|
|
2080
2421
|
*
|
|
2081
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#skip}
|
|
2422
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#skip}
|
|
2082
2423
|
*
|
|
2083
2424
|
* @example
|
|
2084
2425
|
* collection
|
|
@@ -2093,7 +2434,7 @@ declare namespace cloudbase.database {
|
|
|
2093
2434
|
/**
|
|
2094
2435
|
* 指定查询排序条件
|
|
2095
2436
|
*
|
|
2096
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#orderby}
|
|
2437
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#orderby}
|
|
2097
2438
|
*
|
|
2098
2439
|
* @example
|
|
2099
2440
|
* collection
|
|
@@ -2109,7 +2450,7 @@ declare namespace cloudbase.database {
|
|
|
2109
2450
|
/**
|
|
2110
2451
|
* 指定返回结果中文档需返回的字段
|
|
2111
2452
|
*
|
|
2112
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#field}
|
|
2453
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
|
|
2113
2454
|
*
|
|
2114
2455
|
* @example
|
|
2115
2456
|
* collection
|
|
@@ -2124,7 +2465,7 @@ declare namespace cloudbase.database {
|
|
|
2124
2465
|
/**
|
|
2125
2466
|
* 删除查询到的结果
|
|
2126
2467
|
*
|
|
2127
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#remove-1}
|
|
2468
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove-1}
|
|
2128
2469
|
*
|
|
2129
2470
|
* @example
|
|
2130
2471
|
* collection
|
|
@@ -2133,9 +2474,9 @@ declare namespace cloudbase.database {
|
|
|
2133
2474
|
* })
|
|
2134
2475
|
* .remove()
|
|
2135
2476
|
*
|
|
2136
|
-
* @return Promise
|
|
2477
|
+
* @return Promise<RemoveRes> 包含 deleted 字段
|
|
2137
2478
|
*/
|
|
2138
|
-
remove(): Promise<
|
|
2479
|
+
remove(): Promise<RemoveRes>
|
|
2139
2480
|
}
|
|
2140
2481
|
/**
|
|
2141
2482
|
* geo types
|
|
@@ -2150,7 +2491,7 @@ declare namespace cloudbase.database {
|
|
|
2150
2491
|
/**
|
|
2151
2492
|
* 用于表示地理位置点
|
|
2152
2493
|
*
|
|
2153
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#point}
|
|
2494
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#point}
|
|
2154
2495
|
*
|
|
2155
2496
|
* @example
|
|
2156
2497
|
* const point = new db.Geo.Point(lng,lat);
|
|
@@ -2166,7 +2507,7 @@ declare namespace cloudbase.database {
|
|
|
2166
2507
|
/**
|
|
2167
2508
|
* 用于表示地理路径,是由两个或者更多的 Point 组成的线段
|
|
2168
2509
|
*
|
|
2169
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#linestring}
|
|
2510
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#linestring}
|
|
2170
2511
|
*
|
|
2171
2512
|
* @example
|
|
2172
2513
|
* const point = new db.Geo.LineString([pointA,pointB]);
|
|
@@ -2181,7 +2522,7 @@ declare namespace cloudbase.database {
|
|
|
2181
2522
|
/**
|
|
2182
2523
|
* 用于表示地理上的一个多边形
|
|
2183
2524
|
*
|
|
2184
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#polygon}
|
|
2525
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#polygon}
|
|
2185
2526
|
*
|
|
2186
2527
|
* @example
|
|
2187
2528
|
* const point = new db.Geo.Polygon([lineStringA,lineStringB]);
|
|
@@ -2196,7 +2537,7 @@ declare namespace cloudbase.database {
|
|
|
2196
2537
|
/**
|
|
2197
2538
|
* 用于表示多个点 Point 的集合
|
|
2198
2539
|
*
|
|
2199
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multipoint}
|
|
2540
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipoint}
|
|
2200
2541
|
*
|
|
2201
2542
|
* @example
|
|
2202
2543
|
* const point = new db.Geo.MultiPoint([pointA,pointB]);
|
|
@@ -2211,7 +2552,7 @@ declare namespace cloudbase.database {
|
|
|
2211
2552
|
/**
|
|
2212
2553
|
* 用于表示多个地理路径 LineString 的集合
|
|
2213
2554
|
*
|
|
2214
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multilinestring}
|
|
2555
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multilinestring}
|
|
2215
2556
|
*
|
|
2216
2557
|
* @example
|
|
2217
2558
|
* const point = new db.Geo.MultiLineString([lineA,lineB]);
|
|
@@ -2226,7 +2567,7 @@ declare namespace cloudbase.database {
|
|
|
2226
2567
|
/**
|
|
2227
2568
|
* 用于表示多个地理多边形 Polygon 的集合
|
|
2228
2569
|
*
|
|
2229
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multipolygon}
|
|
2570
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipolygon}
|
|
2230
2571
|
*
|
|
2231
2572
|
* @example
|
|
2232
2573
|
* const point = new db.Geo.MultiPolygon([polygonA,polygonB]);
|
|
@@ -2256,19 +2597,19 @@ declare namespace cloudbase.database {
|
|
|
2256
2597
|
/**
|
|
2257
2598
|
* 数据库指令
|
|
2258
2599
|
*
|
|
2259
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
|
|
2600
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
|
|
2260
2601
|
*/
|
|
2261
2602
|
command: ICommand
|
|
2262
2603
|
/**
|
|
2263
2604
|
* 数据库Geo地理位置
|
|
2264
2605
|
*
|
|
2265
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#geo-shu-ju-lei-xing}
|
|
2606
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#geo-shu-ju-lei-xing}
|
|
2266
2607
|
*/
|
|
2267
2608
|
Geo: IGeo
|
|
2268
2609
|
/**
|
|
2269
2610
|
* 根据正则表达式进行筛选
|
|
2270
2611
|
*
|
|
2271
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#regexp}
|
|
2612
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#regexp}
|
|
2272
2613
|
*
|
|
2273
2614
|
* @example
|
|
2274
2615
|
* db.collection('articles').where({
|
|
@@ -2286,7 +2627,7 @@ declare namespace cloudbase.database {
|
|
|
2286
2627
|
/**
|
|
2287
2628
|
* 创建集合的引用
|
|
2288
2629
|
*
|
|
2289
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#collection}
|
|
2630
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#collection}
|
|
2290
2631
|
*
|
|
2291
2632
|
* @example
|
|
2292
2633
|
* const coll = db.collection('demo');
|
|
@@ -2296,6 +2637,82 @@ declare namespace cloudbase.database {
|
|
|
2296
2637
|
* @return 集合的引用
|
|
2297
2638
|
*/
|
|
2298
2639
|
collection(name: string): ICollection
|
|
2640
|
+
/**
|
|
2641
|
+
* 创建集合
|
|
2642
|
+
*
|
|
2643
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#createcollection}
|
|
2644
|
+
*
|
|
2645
|
+
* @example
|
|
2646
|
+
* const result = await db.createCollection('new-collection')
|
|
2647
|
+
*
|
|
2648
|
+
* @param collName 集合名称
|
|
2649
|
+
*
|
|
2650
|
+
* @return Promise<CreateCollectionRes>
|
|
2651
|
+
*/
|
|
2652
|
+
createCollection(collName: string): Promise<CreateCollectionRes>
|
|
2653
|
+
/**
|
|
2654
|
+
* 构造服务端时间对象
|
|
2655
|
+
*
|
|
2656
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#serverdate}
|
|
2657
|
+
*
|
|
2658
|
+
* @example
|
|
2659
|
+
* db.collection('todos').add({
|
|
2660
|
+
* createdAt: db.serverDate()
|
|
2661
|
+
* })
|
|
2662
|
+
*
|
|
2663
|
+
* @param options 可选配置,支持 offset(毫秒偏移量)
|
|
2664
|
+
*
|
|
2665
|
+
* @return 服务端时间对象
|
|
2666
|
+
*/
|
|
2667
|
+
serverDate(options?: { offset?: number }): any
|
|
2668
|
+
/**
|
|
2669
|
+
* 开启一个新事务
|
|
2670
|
+
*
|
|
2671
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#starttransaction}
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* const transaction = await db.startTransaction()
|
|
2675
|
+
* // ... 事务操作
|
|
2676
|
+
* await transaction.commit()
|
|
2677
|
+
*
|
|
2678
|
+
* @return Promise<ITransaction> 事务对象
|
|
2679
|
+
*/
|
|
2680
|
+
startTransaction(): Promise<ITransaction>
|
|
2681
|
+
/**
|
|
2682
|
+
* 执行事务操作,自动处理提交和回滚
|
|
2683
|
+
*
|
|
2684
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#runtransaction}
|
|
2685
|
+
*
|
|
2686
|
+
* @example
|
|
2687
|
+
* const result = await db.runTransaction(async (transaction) => {
|
|
2688
|
+
* const doc = await transaction.collection('accounts').doc('id').get()
|
|
2689
|
+
* await transaction.collection('accounts').doc('id').update({ balance: doc.data.balance - 100 })
|
|
2690
|
+
* return { success: true }
|
|
2691
|
+
* })
|
|
2692
|
+
*
|
|
2693
|
+
* @param callback 事务回调函数
|
|
2694
|
+
* @param times 事务冲突时的重试次数,默认为 3
|
|
2695
|
+
*
|
|
2696
|
+
* @return Promise<any> 事务回调函数的返回值
|
|
2697
|
+
*/
|
|
2698
|
+
runTransaction(callback: (transaction: ITransaction) => Promise<any>, times?: number): Promise<any>
|
|
2699
|
+
/**
|
|
2700
|
+
* 执行 MongoDB 原生命令
|
|
2701
|
+
*
|
|
2702
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#runcommands}
|
|
2703
|
+
*
|
|
2704
|
+
* @example
|
|
2705
|
+
* const result = await db.runCommands({
|
|
2706
|
+
* commands: [
|
|
2707
|
+
* { find: 'users', filter: { age: { $gte: 18 } }, limit: 10 }
|
|
2708
|
+
* ]
|
|
2709
|
+
* })
|
|
2710
|
+
*
|
|
2711
|
+
* @param params 命令参数,包含 commands 数组和可选的 transactionId
|
|
2712
|
+
*
|
|
2713
|
+
* @return Promise<IRunCommandsResult>
|
|
2714
|
+
*/
|
|
2715
|
+
runCommands(params: IRunCommandsReq): Promise<IRunCommandsResult>
|
|
2299
2716
|
}
|
|
2300
2717
|
}
|
|
2301
2718
|
|