Database class
讀取或刪除現有資料庫的作業。
請參閱 資料庫 來建立新的資料庫,以及讀取/查詢所有資料庫;使用 client.databases
。
注意:所有這些作業都會針對固定預算進行呼叫。
您應該設計您的系統,讓這些呼叫以子線性方式調整您的應用程式。
例如,請勿在每個單一 item.read()
呼叫之前呼叫 database.read()
,以確保資料庫存在;在應用程式啟動時執行此動作。
建構函式
Database(Cosmos |
傳回新的 Database 實例。 |
屬性
client | |
containers | 用於建立新的容器,或查詢/讀取所有容器。 使用 範例 建立新的容器
|
id | |
url | 傳回資源的參考 URL。 用於在許可權中連結。 |
users | 用於建立新的使用者,或查詢/讀取所有使用者。 使用 |
方法
container(string) | 用來依標識碼讀取、取代或刪除特定的現有 資料庫。 使用 範例 刪除容器
|
delete(Request |
刪除指定的資料庫。 |
read(Request |
讀取指定資料庫的定義。 |
read |
取得資料庫上的供應專案。 如果不存在,則會傳回未定義的 OfferResponse。 |
user(string) | 用來依標識碼讀取、取代或刪除特定的現有 使用者。 使用 |
建構函式詳細資料
Database(CosmosClient, string, ClientContext)
傳回新的 Database 實例。
注意:意圖是透過 client.database(id)
從 CosmosClient 取得此物件,而不是自行具現化。
new Database(client: CosmosClient, id: string, clientContext: ClientContext)
參數
- client
- CosmosClient
- id
-
string
- clientContext
-
ClientContext
屬性詳細資料
client
containers
用於建立新的容器,或查詢/讀取所有容器。
使用 .database(id)
依標識碼讀取、取代或刪除特定的現有 資料庫。
範例
建立新的容器
const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
containers: Containers
屬性值
id
id: string
屬性值
string
url
傳回資源的參考 URL。 用於在許可權中連結。
string url
屬性值
string
users
方法詳細資料
container(string)
用來依標識碼讀取、取代或刪除特定的現有 資料庫。
使用 .containers
建立新的容器,或查詢/讀取所有容器。
範例
刪除容器
await client.database("<db id>").container("<container id>").delete();
function container(id: string): Container
參數
- id
-
string
傳回
delete(RequestOptions)
刪除指定的資料庫。
function delete(options?: RequestOptions): Promise<DatabaseResponse>
參數
- options
- RequestOptions
傳回
Promise<DatabaseResponse>
read(RequestOptions)
讀取指定資料庫的定義。
function read(options?: RequestOptions): Promise<DatabaseResponse>
參數
- options
- RequestOptions
傳回
Promise<DatabaseResponse>
readOffer(RequestOptions)
取得資料庫上的供應專案。 如果不存在,則會傳回未定義的 OfferResponse。
function readOffer(options?: RequestOptions): Promise<OfferResponse>
參數
- options
- RequestOptions
傳回
Promise<OfferResponse>