跳至正文內容
TursoDB.cn 獨立社群 · MVCC 並行寫入與每 Agent 獨立庫實戰 閱讀解析 →
Turso Cloud API 參考

Turso 平台 API

使用 Turso 平台 API 以程式化方式管理資料庫、群組、組織與權杖。

TypeScript SDK 快速入門

從 JavaScript 或 TypeScript 使用平台 API 最快的方式,就是官方 @tursodatabase/api 用戶端:

npm install @tursodatabase/api
import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: process.env.TURSO_ORG!,
  token: process.env.TURSO_PLATFORM_TOKEN!,
});

// Create a database
const db = await turso.databases.create("user-abc123", { group: "default" });

// Generate a scoped auth token for that database
const { jwt } = await turso.databases.createToken("user-abc123");

// Delete it when no longer needed
await turso.databases.delete("user-abc123");

如需原始 HTTP 參考文件,請參閱下方的資源端點。

常見使用情境

每位使用者一個資料庫 / 每個代理一個資料庫(多租戶)

為每位使用者或每個 AI 代理配置專屬資料庫。每個實體都有自己獨立的 SQLite 資料庫,您可以透過 API 建立、限定權杖範圍並予以銷毀。

import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: process.env.TURSO_ORG!,
  token: process.env.TURSO_PLATFORM_TOKEN!,
});

// On user signup or agent creation — provision a database
const db = await turso.databases.create(`agent-${agentId}`, { group: "default" });

// Generate a scoped token for that database
const { jwt } = await turso.databases.createToken(`agent-${agentId}`);

// Store db.hostname and jwt for the session

資料庫建立後,即可從您的應用程式連線至該資料庫:

平台 / 經銷商

代表您的終端使用者建立並管理資料庫。使用平台 API 在 Turso 之上打造您自己的資料庫即服務(database-as-a-service)。

// List all databases in your organization
const databases = await turso.databases.list();

// Get details for a specific database
const db = await turso.databases.get("customer-db");

API 資源

只要幾個簡單步驟,即可開始將 Turso API 整合至您的平台。

同步自官方 Turso 文件倉庫 ( tursodatabase/turso-docs · MIT 開源授權) 檢視官方原文 ↗
搜尋
按 Esc 關閉 · 由 Pagefind 靜態索引驅動