PocketBase 快速入门教程 - 10分钟构建后端 API
1) 创建集合
Section titled “1) 创建集合”在 Admin UI 中创建集合(例如 posts),添加字段:
title(text)content(editor)cover(file,可选)
2) 写访问规则(示例)
Section titled “2) 写访问规则(示例)”最常见的规则模型:
- 未登录用户:只允许读取已发布内容
- 登录用户:允许创建与更新自己的内容
你可以从「全开放」开始,再逐步收紧规则。
3) 用 Web SDK 读写记录
Section titled “3) 用 Web SDK 读写记录”import PocketBase from "pocketbase";
const pb = new PocketBase("http://127.0.0.1:8090");
const list = await pb.collection("posts").getList(1, 20);4) 文件上传
Section titled “4) 文件上传”const form = new FormData();form.append("title", "Hello");form.append("cover", fileInput.files[0]);await pb.collection("posts").create(form);5) 实时订阅
Section titled “5) 实时订阅”pb.collection("posts").subscribe("*", (e) => { console.log("change:", e.action, e.record);});