turso-drizzle
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "turso-drizzle":https://skillpi.com/zh/skills/deepskill-e4e9893b3f5f821c5cb178a57e4b82ba8494729c53bf8d5aaaf7b1ecb33d095b。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
turso-drizzle:在支持复制的边缘环境中提供类型安全 SQLite 的组合(Turso + Drizzle ORM)。适用于构建边缘兼容应用、在生产中使用 SQLite、多区域数据库或与 Cloudflare Workers 搭配托管数据库的场景,覆盖 Turso 配置、Drizzle 模式定义、使用 drizzle-kit 迁移和边缘部署模式。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 软件、账号及付费要求
- 贝什
- 实测状态
- 未测试
文件浏览
Frontmatter
name: turso-drizzle
description: >-
Turso + Drizzle ORM — type-safe SQLite at the edge with replication. Use
when building edge-compatible applications with type-safe SQL, SQLite in
production, multi-region databases, or Cloudflare Workers with a managed DB.
Covers Turso setup, Drizzle schema definition, migrations with drizzle-kit,
and edge deployment patterns.
license: Apache-2.0
compatibility: "drizzle-orm 0.x, drizzle-kit 0.x, @libsql/client 0.x. Node.js 18+, Bun, Cloudflare Workers."
metadata:
author: terminal-skills
version: "1.0.0"
category: database
tags: ["turso", "drizzle", "sqlite", "edge", "orm", "type-safe"]
use-cases:
- "Set up a type-safe SQLite database with Turso and Drizzle ORM"
- "Run SQLite in production on Cloudflare Workers with Turso replication"
- "Define a Drizzle schema and generate migrations for a Turso database"
- "Query a Turso database with fully typed Drizzle queries"
agents: [claude-code, openai-codex, gemini-cli, cursor]Turso + Drizzle ORM
Overview
Turso is a globally distributed SQLite database (powered by libSQL) with low-latency reads via edge replicas. Drizzle ORM is a lightweight, type-safe SQL query builder and ORM for TypeScript. Together they enable type-safe, edge-compatible SQLite in production.
Installation
npm install drizzle-orm @libsql/client
npm install -D drizzle-kit
# or Bun
bun add drizzle-orm @libsql/client
bun add -d drizzle-kit
Turso Setup
# Install Turso CLI
curl -sSfL https://get.tur.so/install.sh | bash
# Authenticate
turso auth login
# Create a database
turso db create my-app
# Get the database URL
turso db show my-app --url
# libsql://my-app-yourname.turso.io
# Create an auth token
turso db tokens create my-app
# eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9...
Store credentials in .env:
TURSO_DATABASE_URL=libsql://my-app-yourname.turso.io
TURSO_AUTH_TOKEN=eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9...
Database Client
// src/db/client.ts
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import * as schema from "./schema";
const client = createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
});
export const db = drizzle(client, { schema });
Schema Definition
// src/db/schema.ts
import { integer, sqliteTable, text, real } from "drizzle-orm/sqlite-core";
import { relations } from "drizzle-orm";
// Users table
export const users = sqliteTable("users", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
email: text("email").notNull().unique(),
role: text("role", { enum: ["admin", "user", "guest"] }).notNull().default("user"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.$defaultFn(() => new Date()),
});
// Posts table
export const posts = sqliteTable("posts", {
id: integer("id").primaryKey({ autoIncrement: true }),
title: text("title").notNull(),
slug: text("slug").notNull().unique(),
body: text("body").notNull().default(""),
published: integer("published", { mode: "boolean" }).notNull().default(false),
authorId: integer("author_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.$defaultFn(() => new Date()),
});
// Comments table
export const comments = sqliteTable("comments", {
id: integer("id").primaryKey({ autoIncrement: true }),
content: text("content").notNull(),
postId: integer("post_id")
.notNull()
.references(() => posts.id, { onDelete: "cascade" }),
authorId: integer("author_id")
.notNull()
.references(() => users.id),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.$defaultFn(() => new Date()),
});
// Relations (for joins)
export const usersRelations = relations(users, ({ many }) => ({
posts: many(posts),
comments: many(comments),
}));
export const postsRelations = relations(posts, ({ one, many }) => ({
author: one(users, { fields: [posts.authorId], references: [users.id] }),
comments: many(comments),
}));
export const commentsRelations = relations(comments, ({ one }) => ({
post: one(posts, { fields: [comments.postId], references: [posts.id] }),
author: one(users, { fields: [comments.authorId], references: [users.id] }),
}));
// Export inferred types
export type User = typeof users.$inferSelect;
export type NewUser = typeof users.$inferInsert;
export type Post = typeof posts.$inferSelect;
export type NewPost = typeof posts.$inferInsert;
drizzle-kit Configuration
// drizzle.config.ts
import type { Config } from "drizzle-kit";
export default {
schema: "./src/db/schema.ts",
out: "./drizzle",
dialect: "turso",
dbCredentials: {
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
},
} satisfies Config;
Migrations
# Generate migration files from schema changes
npx drizzle-kit generate
# Apply migrations to the database
npx drizzle-kit migrate
# Push schema directly (dev only — no migration files)
npx drizzle-kit push
# Open Drizzle Studio (visual DB browser)
npx drizzle-kit studio
Queries
Insert
import { db } from "./db/client";
import { users, posts } from "./db/schema";
// Insert single row
const [user] = await db
.insert(users)
.values({ name: "Alice", email: "alice@example.com" })
.returning();
// Insert multiple rows
await db.insert(users).values([
{ name: "Bob", email: "bob@example.com" },
{ name: "Carol", email: "carol@example.com" },
]);
// Upsert (insert or update)
await db
.insert(users)
.values({ name: "Alice", email: "alice@example.com" })
.onConflictDoUpdate({
target: users.email,
set: { name: "Alice Updated" },
});
Select
import { eq, and, or, like, desc, count } from "drizzle-orm";
// Select all
const allUsers = await db.select().from(users);
// With condition
const admins = await db
.select()
.from(users)
.where(eq(users.role, "admin"));
// Multiple conditions
const activeAdmins = await db
.select({ id: users.id, name: users.name })
.from(users)
.where(and(eq(users.role, "admin"), like(users.email, "%@company.com")))
.orderBy(desc(users.createdAt))
.limit(10);
// Count
const [{ total }] = await db
.select({ total: count() })
.from(users);
Join
// Inner join
const postsWithAuthors = await db
.select({
postId: posts.id,
title: posts.title,
authorName: users.name,
})
.from(posts)
.innerJoin(users, eq(posts.authorId, users.id))
.where(eq(posts.published, true))
.orderBy(desc(posts.createdAt));
// With relations (using query API)
const usersWithPosts = await db.query.users.findMany({
with: {
posts: {
where: eq(posts.published, true),
orderBy: desc(posts.createdAt),
},
},
});
Update and Delete
import { eq } from "drizzle-orm";
// Update
const [updated] = await db
.update(users)
.set({ role: "admin" })
.where(eq(users.id, 1))
.returning();
// Delete
await db.delete(posts).where(eq(posts.authorId, 1));
Cloudflare Workers Pattern
In Cloudflare Workers, create the client per request (no persistent connections):
// src/index.ts
import { Hono } from "hono";
import { createClient } from "@libsql/client/http"; // Use HTTP client for edge
import { drizzle } from "drizzle-orm/libsql";
import * as schema from "./db/schema";
import { eq } from "drizzle-orm";
type Env = {
TURSO_DATABASE_URL: string;
TURSO_AUTH_TOKEN: string;
};
const app = new Hono<{ Bindings: Env }>();
// Middleware: attach db to context
app.use("*", async (c, next) => {
const client = createClient({
url: c.env.TURSO_DATABASE_URL,
authToken: c.env.TURSO_AUTH_TOKEN,
});
c.set("db", drizzle(client, { schema }));
await next();
});
app.get("/users", async (c) => {
const db = c.get("db");
const allUsers = await db.select().from(schema.users);
return c.json({ users: allUsers });
});
app.get("/users/:id", async (c) => {
const db = c.get("db");
const id = Number(c.req.param("id"));
const [user] = await db
.select()
.from(schema.users)
.where(eq(schema.users.id, id));
if (!user) return c.json({ error: "Not found" }, 404);
return c.json({ user });
});
export default app;
# wrangler.toml
name = "my-api"
main = "src/index.ts"
compatibility_date = "2024-11-01"
compatibility_flags = ["nodejs_compat"]
[vars]
TURSO_DATABASE_URL = "libsql://my-app-yourname.turso.io"
# Set TURSO_AUTH_TOKEN via: wrangler secret put TURSO_AUTH_TOKEN
Embedded Replica Pattern
For maximum read performance with Turso:
// src/db/client.ts — Node.js / Bun only (not edge)
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import * as schema from "./schema";
const client = createClient({
url: "file:./local-replica.db",
syncUrl: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
syncInterval: 60, // Sync every 60s
});
// Initial sync on startup
await client.sync();
export const db = drizzle(client, { schema });
Guidelines
- Use
drizzle-orm/libsqladapter for both local SQLite and Turso cloud. - Use
@libsql/client/http(not the default) on Cloudflare Workers — native bindings are not supported. - Always use
.returning()after insert/update to get the created/updated row. - Define
relations()for clean join queries with the Drizzle query API. - Run
drizzle-kit generatethendrizzle-kit migratefor production migrations — neverpushin production. - Store
TURSO_AUTH_TOKENas a secret (wrangler secret put) — never inwrangler.toml. - Use embedded replicas for Node.js/Bun apps that need fast reads with global replication.
- Export
$inferSelectand$inferInserttypes from the schema for use in application code.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Turso + Drizzle ORM 的完整开发指南,涵盖数据库配置、模式定义、迁移、查询、边缘部署等核心场景
- 适用于边缘计算、生产环境 SQLite、多区域数据库等明确需求,解决开发者实际痛点
亮点
- description 明确描述了适用场景(边缘兼容应用、生产环境 SQLite、多区域数据库、Cloudflare Workers),覆盖多种变体,边界清晰
亮点
- 文档结构清晰,分多个逻辑章节,步骤完整,有端到端示例,frontmatter 完整,单文件未超过 500 行
亮点
- 工具来源明确(npm/bun 包、Turso CLI),参数正确,覆盖了主要异常(如 Cloudflare Workers 使用 HTTP client、生产环境迁移规范、密钥存储建议)
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 33, 34, 177, 180, 183 行 -
账号、密钥或授权
使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。
主文档提及 · 第 62 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- get.tur.so
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
贝什
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。