NW DB ドキュメント
NW DB API、SDK、機能の完全ガイド
はじめに
アカウント登録、ワークスペース作成、APIキー取得まで数分で完了します。
- 1. nw-db-webでGoogleまたはメールでアカウントを作成します。
- 2. ダッシュボードからワークスペースを作成します。
- 3. 設定 > APIキーからAPIキーを作成します。
- 4. リクエストのX-API-Keyヘッダーにキーを指定します。
認証
NW DBは2つの認証方式をサポートしています:
- Bearerトークン: AuthorizationヘッダーにFirebase IDトークンを指定
- APIキー: X-API-Keyヘッダーに生成したキーを指定
shell
# Bearer token authentication
curl https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/tables \
-H "Authorization: Bearer <FIREBASE_ID_TOKEN>" \
-H "X-Workspace-ID: <WORKSPACE_ID>"
# API key authentication
curl https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/tables \
-H "X-API-Key: nwdb_your_key_here" \
-H "X-Workspace-ID: <WORKSPACE_ID>"REST API
PostgreSQLスキーマから自動生成されるREST API。CRUD、フィルタリング、ページネーション対応。
List Tables
shell
curl https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/tables \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123"Create Table
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/tables \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{
"name": "customers",
"columns": [
{ "name": "name", "type": "string", "required": true },
{ "name": "email", "type": "string", "required": true },
{ "name": "age", "type": "number" }
]
}'Create Record
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/records/customers/records \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{ "name": "John", "email": "john@example.com", "age": 30 }'List Records
shell
curl "https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/records/customers/records?limit=50&offset=0" \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123"Execute SQL
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/query \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{ "sql": "SELECT * FROM customers WHERE age > 25 LIMIT 10" }'GraphQL
PostGraphile経由の自動生成GraphQL API。サブスクリプション、ミューテーション、クエリ対応。
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/proxy/graphql \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{
"query": "{ allCustomers(first: 10) { nodes { name email age } } }"
}'MCP (Model Context Protocol)
Claude、Geminiなどの AIエージェントをデータベースに直接接続します。
Claude Desktop Config
json
{
"mcpServers": {
"nwdb": {
"url": "https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/mcp/sse",
"headers": {
"X-API-Key": "nwdb_your_key_here",
"X-Workspace-ID": "your_workspace_id"
}
}
}
}Available Tools
| Tool | Description |
|---|---|
| query | Execute SQL query |
| list_tables | List all tables |
| describe_table | Get table schema |
| insert_record | Insert a record |
| vector_search | Semantic similarity search |
| upload_file | Upload file to storage |
Execute MCP Tool via API
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/mcp/call \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{
"tool": "query",
"arguments": { "sql": "SELECT * FROM customers LIMIT 5" }
}'ベクトル検索
pgvectorによる類似検索。Embeddingの保存とセマンティック検索が可能です。
Create Collection
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/vectors/collections \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{ "name": "documents", "dimensions": 768 }'Upsert Vector
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/vectors/collections/documents/upsert \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{
"id": "doc-1",
"embedding": [0.1, 0.2, 0.3, ...],
"content": "NW DB is an AI-native database",
"metadata": { "source": "docs", "category": "product" }
}'Search
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/vectors/collections/documents/search \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{
"embedding": [0.1, 0.2, 0.3, ...],
"topK": 10
}'AIエージェント
クレンジング、正規化、マスキング、ベクトル化、メタデータ抽出の自動パイプライン。
| Agent | Description |
|---|---|
| cleansing | Deduplicate, fill missing values, standardize formats |
| normalization | Normalize addresses, company names, dates, categories |
| masking | Auto-detect and mask PII (email, phone, address) |
| vectorization | Auto-generate embeddings for text columns |
| metadata | Infer column semantics, detect relationships, build catalog |
Trigger Agent
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/agents/run/cleansing \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '{ "reason": "Monthly data cleanup" }'Check Agent Status
shell
curl https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/agents/status \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123"CSV / JSONインポート
CSVまたはJSON形式でデータを一括インポートします。
Import CSV
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/import/csv/customers \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: text/csv" \
--data-binary @customers.csvImport JSON
shell
curl -X POST https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/import/json/customers \
-H "X-API-Key: nwdb_xxx" \
-H "X-Workspace-ID: ws_abc123" \
-H "Content-Type: application/json" \
-d '[
{ "name": "John", "email": "john@example.com", "age": 30 },
{ "name": "Jane", "email": "jane@example.com", "age": 25 }
]'リアルタイム
WebSocketまたはServer-Sent Eventsでデータベース変更をサブスクライブします。
javascript
// WebSocket connection
const ws = new WebSocket(
"wss://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/realtime/ws"
);
ws.onopen = () => {
ws.send(JSON.stringify({
type: "subscribe",
table: "customers",
apiKey: "nwdb_your_key_here",
workspaceId: "ws_abc123",
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Change:", data);
// { type: "INSERT", table: "customers", record: {...} }
};SDK
Node.jsおよびPython向け公式SDKを提供しています。
Node.js
shell
npm install nwdb-sdkjavascript
import { NWDBClient } from "nwdb-sdk";
const db = new NWDBClient({
apiKey: "nwdb_your_key_here",
workspaceId: "ws_abc123",
});
// List tables
const tables = await db.tables.list();
// Query records
const customers = await db.from("customers")
.select("*")
.where("age", ">", 25)
.limit(10);
// Vector search
const results = await db.vectors
.collection("documents")
.search({ query: "AI database", topK: 5 });Python
shell
pip install nwdbpython
from nwdb import NWDBClient
db = NWDBClient(
api_key="nwdb_your_key_here",
workspace_id="ws_abc123",
)
# List tables
tables = db.tables.list()
# Query records
customers = db.query("SELECT * FROM customers WHERE age > 25 LIMIT 10")
# Vector search
results = db.vectors.collection("documents").search(
query="AI database",
top_k=5,
)料金
Standardプラン月額5,500円+従量課金。
Standard
5,500 JPY / month
従量課金表
| 項目 | 含む | 超過単価 |
|---|---|---|
| Database Storage | 3 GB | 110 JPY / GB |
| File Storage | 500 MB | 55 JPY / GB |
| API Calls | 100K / month | 1.1 JPY / 1K calls |
| Vector Writes | 10K / month | 5.5 JPY / 1K writes |
| Vector Queries | 10K / month | 3.3 JPY / 1K queries |
| AI Agent Processing | 10K rows / month | 11 JPY / 1K rows |
| Background Jobs | 60 min / month | 1.1 JPY / min |
対話型APIリファレンス(Swagger UI)
Swagger UIshell
# OpenAPI spec
curl https://nw-db-api-984843242141.asia-northeast1.run.app/api/v1/docs/openapi.json