Turso Cloud API 參考 介面資源 資料庫
取得資料庫用量
取得資料庫在指定時間區間內的活動用量。
GET
https://api.turso.tech/v1/organizations/{organizationSlug}/databases/{databaseName}/usage curl -L -X GET 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases/{databaseName}/usage?from=2023-01-01T00:00:00Z&to=2023-02-01T00:00:00Z' \
-H 'Authorization: Bearer TOKEN'
import { createClient } from "@tursodatabase/api";
const turso = createClient({
org: "...",
token: "",
});
const usageStatsWithDate = await turso.databases.usage("my-db");
const usageStatsWithDate = await turso.databases.usage("my-db", {
from: new Date("2023-01-01"),
to: new Date("2023-02-01"),
});
const usageStatsWithString = await turso.databases.usage("my-db", {
from: "2023-01-01T00:00:00Z",
to: "2023-02-01T00:00:00Z",
});
OpenAPI
openapi: 3.0.1
info:
title: Turso Platform API
description: 此處為 API 說明
license:
name: MIT
version: 0.1.0
servers:
- url: https://api.turso.tech
description: Turso's Platform API
security: []
paths:
/v1/organizations/{organizationSlug}/databases/{databaseName}/usage:
get:
summary: 取得資料庫用量
description: 取得資料庫在指定時間區間內的活動用量。
operationId: getDatabaseUsage
parameters:
- $ref: '#/components/parameters/organizationSlug'
- $ref: '#/components/parameters/databaseName'
- name: from
in: query
schema:
type: string
format: date-time
description: >-
以 [ISO
8601](https://en.wikipedia.org/wiki/ISO_8601) 格式指定要**開始**取得用量的日期時間。若未提供,預設為目前曆月。範例:
`2023-01-01T00:00:00Z`
- name: to
in: query
schema:
type: string
format: date-time
description: >-
以 [ISO
8601](https://en.wikipedia.org/wiki/ISO_8601) 格式指定要**結束**取得用量的日期時間。若未提供,預設為目前曆月。範例:
`2023-02-01T00:00:00Z`
responses:
'200':
description: 成功回應
content:
application/json:
schema:
type: object
properties:
database:
$ref: '#/components/schemas/DatabaseUsageOutput'
type: object
description: >-
資料庫用量物件,包含讀取與寫入列數的總計及各執行個體用量,以及總儲存大小(以位元組為單位)。
'400':
description: 錯誤的請求
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: 錯誤訊息
example: >-
invalid from parameter: parsing time "2023-12-12T00:00:00"
as "2006-01-02T15:04:05Z07:00": cannot parse "" as
"Z07:00"
'404':
$ref: '#/components/responses/DatabaseNotFoundResponse'
components:
parameters:
organizationSlug:
in: path
name: organizationSlug
required: true
schema:
type: string
description: 組織或使用者帳戶的 slug。
databaseName:
name: databaseName
in: path
required: true
schema:
type: string
description: 資料庫的名稱。
schemas:
DatabaseUsageOutput:
type: object
properties:
uuid: 2c439770-a039-437c-b074-b92eb9f47cc0
instances:
type: array
description: 目前資料庫各執行個體的用量物件。
items:
type: object
properties:
uuid:
type: string
description: 執行個體的通用唯一識別碼(UUID)。
example: cd831986-94e5-11ee-a6fe-7a52e1f7759a
usage:
$ref: '#/components/schemas/DatabaseUsageObject'
description: 目前資料庫執行個體的用量。
example:
- uuid: cd831986-94e5-11ee-a6fe-7a52e1f7759a
usage:
rows_read: 0
rows_written: 0
storage_bytes: 4096
bytes_synced: 0
- uuid: 0be90471-6906-11ee-8553-eaa7715aeaf2
usage:
rows_read: 0
rows_written: 0
storage_bytes: 4096
bytes_synced: 0
total:
$ref: '#/components/schemas/DatabaseUsageObject'
description: 資料庫的總用量。
example:
rows_read: 0
rows_written: 0
storage_bytes: 8192
bytes_synced: 0
DatabaseUsageObject:
type: object
properties:
rows_read:
type: integer
example: 0
description: 該時間區間內讀取的總列數。
rows_written:
type: integer
example: 0
description: 該時間區間內寫入的總列數。
storage_bytes:
type: integer
example: 0
description: 使用的總儲存空間。
bytes_synced:
type: integer
example: 0
description: 同步的總位元組數。
responses:
DatabaseNotFoundResponse:
description: 找不到資料庫
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: 錯誤訊息
example: >-
could not find database with name [databaseName]: record not
found
同步自官方 Turso 文件倉庫 (
tursodatabase/turso-docs
· MIT 開源授權)
檢視官方原文 ↗