d1-database
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "d1-database":https://skillpi.com/zh/skills/deepskill-098e1e5cb65724f4775e9e5dd62ab9f8939f604130e3cf3713afec94fa674bc7。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 Cloudflare D1 在无服务器环境构建应用 —— 在边缘节点上运行的 SQLite。适用于有关“无服务器数据库”、“Cloudflare D1”、“边缘节点上的 SQLite”、“Workers 数据库”、“边缘数据库”或“无服务器 SQL”的询问。涵盖模式设置、查询、迁移、Workers 集成以及使用 Drizzle ORM。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 适合谁
- 翻译待完成,请参阅来源文档。
- 软件、账号及付费要求
- 贝什
- 实测状态
- 未测试
文件浏览
Frontmatter
name: d1-database
description: >-
Build serverless applications with Cloudflare D1 — SQLite at the edge. Use
when someone asks to "serverless database", "Cloudflare D1", "SQLite at the
edge", "database for Workers", "edge database", or "serverless SQL". Covers
schema setup, queries, migrations, Workers integration, and Drizzle ORM.
license: Apache-2.0
compatibility: "Cloudflare Workers. Wrangler CLI. SQLite-compatible."
metadata:
author: terminal-skills
version: "1.0.0"
category: data-ai
tags: ["database", "cloudflare", "d1", "sqlite", "edge"]Cloudflare D1
Overview
D1 is Cloudflare's serverless SQLite database — runs at the edge alongside Workers. Zero connection overhead (it's in the same data center as your Worker), SQLite query syntax, automatic replication, and pay-per-query pricing. Perfect for read-heavy workloads, content sites, and applications where latency matters.
When to Use
- Building on Cloudflare Workers and need a database
- Read-heavy applications (blogs, content sites, APIs)
- Want SQLite simplicity with global distribution
- Serverless applications with no connection pooling headaches
- Edge-first applications where database latency matters
Instructions
Setup
# Create a D1 database
npx wrangler d1 create my-database
# Add to wrangler.toml
# wrangler.toml
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "xxxx-xxxx-xxxx"
Schema and Migrations
# Create migration
npx wrangler d1 migrations create my-database init
-- migrations/0001_init.sql
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
created_at TEXT DEFAULT (datetime('now'))
);
CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
content TEXT NOT NULL,
author_id INTEGER NOT NULL REFERENCES users(id),
published BOOLEAN DEFAULT FALSE,
created_at TEXT DEFAULT (datetime('now'))
);
CREATE INDEX idx_posts_author ON posts(author_id);
CREATE INDEX idx_posts_published ON posts(published);
# Apply migrations
npx wrangler d1 migrations apply my-database
Queries in Workers
// src/index.ts — Cloudflare Worker with D1
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/api/posts" && request.method === "GET") {
const { results } = await env.DB.prepare(
`SELECT posts.*, users.name as author_name
FROM posts
JOIN users ON posts.author_id = users.id
WHERE posts.published = TRUE
ORDER BY posts.created_at DESC
LIMIT ?`
).bind(20).all();
return Response.json({ posts: results });
}
if (url.pathname === "/api/posts" && request.method === "POST") {
const body = await request.json();
const result = await env.DB.prepare(
"INSERT INTO posts (title, content, author_id) VALUES (?, ?, ?) RETURNING *"
).bind(body.title, body.content, body.authorId).first();
return Response.json({ post: result }, { status: 201 });
}
return new Response("Not found", { status: 404 });
},
};
With Drizzle ORM
// src/db/schema.ts — Drizzle schema for D1
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
export const users = sqliteTable("users", {
id: integer("id").primaryKey({ autoIncrement: true }),
email: text("email").notNull().unique(),
name: text("name").notNull(),
});
export const posts = sqliteTable("posts", {
id: integer("id").primaryKey({ autoIncrement: true }),
title: text("title").notNull(),
content: text("content").notNull(),
authorId: integer("author_id").notNull().references(() => users.id),
published: integer("published", { mode: "boolean" }).default(false),
});
// src/index.ts — Using Drizzle with D1
import { drizzle } from "drizzle-orm/d1";
import { eq } from "drizzle-orm";
import * as schema from "./db/schema";
export default {
async fetch(request: Request, env: Env) {
const db = drizzle(env.DB, { schema });
const publishedPosts = await db.query.posts.findMany({
where: eq(schema.posts.published, true),
with: { author: true },
orderBy: (posts, { desc }) => [desc(posts.id)],
limit: 20,
});
return Response.json({ posts: publishedPosts });
},
};
Examples
Example 1: Build a blog API on the edge
User prompt: "Create a blog API with Cloudflare Workers and D1 for posts and comments."
The agent will create D1 schema, migrations, CRUD endpoints in a Worker, and Drizzle ORM integration.
Example 2: User authentication with D1
User prompt: "Store user accounts in D1 with email/password auth."
The agent will create users table, password hashing with Web Crypto API, session management, and auth middleware.
Guidelines
- SQLite syntax — D1 is SQLite under the hood
- Prepared statements with
.bind()— prevent SQL injection .first()for single row,.all()for multiple — query methods- Migrations via Wrangler — version-controlled schema changes
- Read replicas are automatic — D1 replicates globally
- Write latency is higher — writes go to primary; reads are fast everywhere
- 5MB row limit — not for large blobs
- Free tier: 5M reads, 100K writes/day — generous for small apps
- Drizzle ORM recommended — type-safe queries with D1 adapter
- Local development —
wrangler devuses local SQLite
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Cloudflare D1 的完整使用指南,涵盖数据库创建、迁移、查询、ORM 集成等核心功能
- 面向边缘计算和无服务器架构开发者,具有明确实用价值和广泛适用场景
亮点
- 触发词覆盖完整且精准,包含 "serverless database"、"Cloudflare D1"、"SQLite at the edge" 等多种变体
- 边界清晰,专门针对 D1 使用场景,不易与其他 Skill 重叠
待提升项
-
缺少明确的出口条件说明 原报告严重程度:轻微
文档中未明确说明何时应停止使用该 Skill 或转向其他解决方案
改进建议:在 Guidelines 或新增章节中补充出口条件,如数据量超过限制、需要复杂事务等场景
-
When to Use 章节说明不够详细 原报告严重程度:轻微
When to Use 部分列出了适用场景,但缺乏对不适用场景的明确说明
改进建议:补充不适用场景说明,帮助用户更准确判断是否使用该 Skill
亮点
- Phase/步骤清晰完整,从 Setup 到 Examples 形成完整闭环
- frontmatter 完整规范,包含必要的元数据信息
- 提供端到端示例,增强实用性和可操作性
亮点
- 工具来源明确(Wrangler CLI, Drizzle ORM),参数正确,代码示例完整可执行
- 覆盖主要异常场景和最佳实践,包含安全建议(SQL injection 防护)和限制说明
- 提供本地开发方案和免费 tier 信息,增强实用性
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 37, 54, 81 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
贝什
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。