PocketBase 后端开发指南

SKILL开发

原名 pocketbase-skill · 标识 pocketbase

开发 未标注权限 许可证不明确
安装这个技能

围绕 PocketBase 后端开发提供配置与部署参考,可用来设计集合结构、设置认证与接口访问规则,并接入 JavaScript、Dart 等客户端 SDK 或 REST 接口进行

一句话选型结论

按资料字段整理

PocketBase 后端开发指南是开发类的 Agent Skill,安装方式未标注,权限级别未标注,许可证不明确,有可直接复制的安装命令。技能本质是给模型读的说明书,效果取决于模型与客户端;装完先用一个小任务验证,再放进正式流程。

分类开发 安装方式未标注 权限级别未标注权限 许可证许可证不明确
累计安装 未标注 本周 未标注
GitHub 星标 未标注 仓库 未标注
下载量 未标注 技能市场下载数
权限级别 未标注权限 安装前请确认风险范围
许可证 许可证不明确 未说明

安装

未标注
在支持 Skills 的客户端里执行,装完问一句「你有哪些技能」验证
skillhub install user_a9d3dfac/pocketbase-skill
  1. 1
    确认客户端支持

    确认你的客户端支持 Skills(Claude、Codex、Cursor 等),并升级到较新的版本。

  2. 2
    拿到技能文件

    执行上面的命令安装;也可以把仓库里的 SKILL.md 手动放进客户端的 skills 目录。

  3. 3
    刷新技能列表

    重新打开客户端,或刷新技能列表,让新放进来的技能被加载。

  4. 4
    验证是否生效

    问一句「你有哪些技能」,确认列表里出现它,再拿一个小任务试跑。

技能档案

开发
字段来自技能仓库与公开索引,中文说明由本站标注
作者 / 维护方user_a9d3dfac仓库 未标注 · 版本 未标注
宿主客户端未标注技能可被这些客户端加载
安装方式未标注安装包 community
权限级别未标注权限安装前请确认风险范围
许可证未说明许可证不明确,商用前请自行确认条款
仓库可用性available技能仓库当前是否可访问
最近核验2026-11-06上游最后核验时间 · 数据更新 2026-11-06
正文体量16.9 KBSKILL.md 原文大小,越大说明说明书写得越细

能做什么

0 项能力
上游给出的能力概览与适用场景
设计集合数据表结构配置认证与访问规则接入客户端 SDK 联调

典型使用场景

3 类
按分类整理的常见用法,具体以 SKILL.md 为准
写代码与改 bug

按需求补代码、定位并修掉报错。

读仓库与生成改动

让模型读懂项目结构,再给出可落地的改动。

跑测试与排查故障

按现象排查问题,补测试用例并复跑。

选择建议

装之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有可直接复制的安装命令,不用自己翻文档找入口。

先想清楚的地方

  • 没有标注权限级别,实际能做什么要装好后确认。
  • 许可证不明确,商用或二次分发前先到仓库确认条款。
  • 没有做站内核验,内容以作者仓库为准。
  • 技能只是说明书,实际效果取决于模型与客户端,装完先用小任务试一遍。

更适合

  • 需要在开发场景里给模型补一套做法的人。
  • 愿意先读一遍 SKILL.md、确认它会让模型做什么的人。

不太适合

  • 对许可证要求很严、必须明确可商用的人。
  • 只想装完就自动变强、不打算看说明书的人。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
技能权限级别安装方式累计安装宿主客户端安装命令
PocketBase 后端开发指南当前 未标注权限 未标注 未标注 未标注 有
技能审查员 浏览器控制 ClawHub 市场 877.9 万 OpenClaw 有
Vercel React 最佳实践 浏览器控制 GitHub 仓库 849.1 万 Codex、Claude、Cursor 有
GitHub 代码协作 联网访问 ClawHub 市场 763.3 万 OpenClaw 有
网页设计指南 联网访问 GitHub 仓库 668.6 万 Codex、Claude、Cursor 有
本体论 只读 ClawHub 市场 663.7 万 OpenClaw 有

SKILL.md 全文

16.9 KB
模型实际读到的说明书原文,来自技能仓库

PocketBase Development Guide

PocketBase is an open-source, lightweight backend packaged as a single executable or embeddable Go package. It bundles an embedded SQLite database, user authentication, file storage, a real-time event engine, an administrative dashboard UI, and RESTful APIs with official client SDKs.

PocketBase supports two primary operating modes:
1. Standalone Backend with Client SDKs: Run PocketBase as an independent service and interact via client SDKs (JavaScript/TypeScript, Dart/Flutter) or HTTP REST calls.
2. Embedded Go Framework: Import github.com/pocketbase/pocketbase into a Go project to extend server logic with custom endpoints, lifecycle event hooks, background crons, and custom CLI tools.


Quick Navigation

  • Getting Started & Setup: Standalone Quickstart | Embedded Go Setup | CLI Commands
  • Data Modeling & Access Control: Collections & Schemas | API Security Rules | Schema Templates
  • Client Integration (SDKs & REST): JavaScript / TypeScript SDK | Dart / Flutter SDK | REST API Reference | Realtime
  • Go Extension Framework: Lifecycle & Event Hooks | Routing & Middleware | Database & Transactions | Migrations | CLI Commands
  • Production & Maintenance: Going to Production | Docker Setup | Caddy HTTPS | Data Migration

1. Getting Started & Setup

Standalone Quickstart

  1. Download Binary or Run via Docker:
    bash # Option A: Run via Docker docker run -d \ -v pb_data:/pb_data \ -p 8090:8090 \ --name pocketbase \ ghcr.io/pocketbase/pocketbase:latest serve --http=0.0.0.0:8090

  2. Access the Admin Dashboard:
    - Open http://127.0.0.1:8090/_/ in your browser.
    - Create the initial superuser account.

  3. Detailed reference: Getting Started and CLI Commands.

Embedded Go Setup

When building a customized backend, PocketBase can be embedded directly into your Go application:

  1. Initialize Module & Install Dependencies:
    bash go mod init myapp go get github.com/pocketbase/pocketbase@latest

  2. Minimal main.go:
    ```go
    package main

import (
"log"
"net/http"

   "github.com/pocketbase/pocketbase"
   "github.com/pocketbase/pocketbase/core"

)

func main() {
app := pocketbase.New()

   // Register custom route during serve
   app.OnServe().BindFunc(func(se *core.ServeEvent) error {
       se.Router.GET("/api/healthz", func(e *core.RequestEvent) error {
           return e.JSON(http.StatusOK, map[string]string{"status": "ok"})
       })
       return se.Next()
   })

   if err := app.Start(); err != nil {
       log.Fatal(err)
   }

}
```

  1. Start the Application:
    bash go run main.go serve --http=0.0.0.0:8090
    For in-depth extension guides, see Go Overview.

2. Data Modeling & Collections

PocketBase supports three collection types:
- Base Collection: Standard data tables for posts, comments, orders, etc.
- Auth Collection: Stores credentials, handles logins, OAuth2, and session tokens.
- View Collection: Read-only SQL views for reports, aggregations, or denormalized data.

System Fields

Every record contains the following built-in fields:
- id (15-character alphanumeric unique identifier)
- created (ISO 8601 UTC timestamp string)
- updated (ISO 8601 UTC timestamp string)
Auth collections additionally contain email, emailVisibility, verified, tokenKey, and password management fields.

Common Relations Pattern

When linking collections, use the relation field type:
- Single Relation: Set maxSelect = 1 (e.g., post.author -> single user id).
- Multiple Relation: Set maxSelect > 1 or empty (e.g., post.tags -> array of tag ids).
- When querying, use expand (e.g., author,comments(post).user).
- Reference guide: Working with Relations and Collections Guide.


3. Security & API Rules

API rules determine who can read, create, update, or delete records. Each collection has 5 rule slots: List, View, Create, Update, and Delete.

  • Empty / Blank rule (""): Anyone (including unauthenticated public users) can perform the action.
  • null: The action is locked from the public API; only superusers or Go hooks can access it.
  • Rule Expression: Dynamic evaluation based on @request and collection fields.

Common Rule Patterns

# Only authenticated users
@request.auth.id != ""

# Record owner only
@request.auth.id = author.id

# User can update only their own profile
@request.auth.id = id

# Role-based access
@request.auth.role = "admin"

# Relational check: User belongs to the same organization
@request.auth.organization = organization.id

# Field immutability: Ensure author field cannot be changed on update
@request.data.author:isset = false || @request.data.author = author

Detailed guides: API Rules & Filters and Security Rules Patterns.


4. Client SDKs & API Integration

JavaScript / TypeScript SDK

Install via npm:

npm install pocketbase

Initialization & Authentication

import PocketBase from 'pocketbase';

const pb = new PocketBase('http://127.0.0.1:8090');

// Login with email and password
const authData = await pb.collection('users').authWithPassword('user@example.com', 'password123');
console.log('Logged in user ID:', pb.authStore.record?.id);

// Check if currently authenticated
if (pb.authStore.isValid) {
  // auth headers automatically attached to requests
}

// Logout
pb.authStore.clear();

CRUD Operations

// List / Paginate records with filter and sort
const resultList = await pb.collection('posts').getList(1, 20, {
  filter: 'status = "published" && created >= "2026-01-01"',
  sort: '-created',
  expand: 'author,categories',
});

// Get single record
const record = await pb.collection('posts').getOne('RECORD_ID', {
  expand: 'author',
});

// Create record
const newPost = await pb.collection('posts').create({
  title: 'Hello World',
  content: 'PocketBase is awesome',
  status: 'published',
  author: pb.authStore.record?.id,
});

// Update record
await pb.collection('posts').update('RECORD_ID', {
  title: 'Updated Title',
});

// Delete record
await pb.collection('posts').delete('RECORD_ID');

Realtime Subscriptions

// Subscribe to all changes in a collection
await pb.collection('posts').subscribe('*', (e) => {
  console.log('Action:', e.action); // 'create', 'update', or 'delete'
  console.log('Record:', e.record);
});

// Subscribe to a specific record
await pb.collection('posts').subscribe('RECORD_ID', (e) => {
  console.log('Post updated:', e.record);
});

// Unsubscribe
await pb.collection('posts').unsubscribe('*');

File Uploads & URLs

// Uploading files via FormData
const formData = new FormData();
formData.append('title', 'My Document');
formData.append('file', fileInput.files[0]);

const record = await pb.collection('documents').create(formData);

// Generating file access URL
const fileUrl = pb.files.getURL(record, record.file, { thumb: '100x100' });

Full SDK documentation: JavaScript SDK, Dart SDK, API Records, and API Realtime.


5. Extending PocketBase with Go

PocketBase can be embedded and customized with Go hooks, router handlers, and database utilities.

Event Hooks in Go

Hooks intercept PocketBase operations before or after execution. Always call e.Next() to continue the chain.

// Intercept record creation to validate or enrich data
app.OnRecordCreateRequest("posts").BindFunc(func(e *core.RecordRequestEvent) error {
    if e.Auth != nil {
        e.Record.Set("author", e.Auth.Id)
    }

    // Custom validation
    if len(e.Record.GetString("title")) < 3 {
        return e.BadRequestError("Title is too short", nil)
    }

    return e.Next()
})

// Trigger post-creation side effects (e.g., logging, async notification)
app.OnRecordCreate("posts").BindFunc(func(e *core.RecordCreateEvent) error {
    e.App.Logger().Info("Post created", "id", e.Record.Id, "title", e.Record.GetString("title"))
    return e.Next()
})

// Intercept authentication
app.OnRecordAuth().BindFunc(func(e *core.RecordAuthEvent) error {
    e.App.Logger().Info("User authenticated", "email", e.Record.GetString("email"))
    return e.Next()
})

Reference: Go Event Hooks.

Custom Routes & Middleware in Go

Register custom HTTP endpoints inside the OnServe event:

app.OnServe().BindFunc(func(se *core.ServeEvent) error {
    // Add custom GET route
    se.Router.GET("/api/stats", func(e *core.RequestEvent) error {
        count, err := e.App.CountRecords("posts")
        if err != nil {
            return e.InternalServerError("failed to count posts", err)
        }

        return e.JSON(http.StatusOK, map[string]any{
            "total_posts": count,
            "user":        e.Auth != nil,
        })
    })

    // Custom POST route with body parsing
    se.Router.POST("/api/feedback", func(e *core.RequestEvent) error {
        var data struct {
            Message string `json:"message"`
        }
        if err := e.BindBody(&data); err != nil {
            return e.BadRequestError("invalid request body", err)
        }

        e.App.Logger().Info("Feedback received", "message", data.Message)
        return e.NoContent(http.StatusOK)
    })

    return se.Next()
})

Reference: Go Routing.

Database Operations with dbx

Use PocketBase's built-in DB engine and query builder:

import "github.com/pocketbase/dbx"

// 1. Fetch single record
post, err := app.FindRecordById("posts", "RECORD_ID")

// 2. Fetch multiple records with filter and pagination
records, err := app.FindRecordsByFilter(
    "posts",
    "status = {:status}",
    "-created",
    20, // limit
    0,  // offset
    dbx.Params{"status": "published"},
)

// 3. Create a record programmatically
postsCol, err := app.FindCollectionByNameOrId("posts")
if err != nil {
    return err
}
newRecord := core.NewRecord(postsCol)
newRecord.Set("title", "Server Generated")
newRecord.Set("status", "published")
if err := app.Save(newRecord); err != nil {
    return err
}

// 4. Run inside an ACID transaction
err = app.RunInTransaction(func(txApp core.App) error {
    record, err := txApp.FindRecordById("posts", "RECORD_ID")
    if err != nil {
        return err
    }
    record.Set("views", record.GetInt("views")+1)
    return txApp.Save(record)
})

Reference: Go Database Operations.

Cron Jobs & Console Commands

// Add a recurring background job
app.Cron().MustAdd("cleanup-task", "@every 30m", func() {
    app.Logger().Info("Running background cleanup...")
})

// Register custom CLI commands via Cobra
import "github.com/spf13/cobra"

app.RootCmd.AddCommand(&cobra.Command{
    Use:   "seed",
    Short: "Seed initial test data",
    RunE: func(cmd *cobra.Command, args []string) error {
        // seed logic
        return nil
    },
})

Reference: Go Console Commands and Go Overview.


6. Production Deployment

Production Checklist

  1. Reverse Proxy & TLS: Use Caddy or Nginx in front of PocketBase for automatic SSL termination and rate limiting.
  2. Persistent Storage: Ensure pb_data directory is on persistent SSD storage.
  3. Admin Security: Change default admin credentials and enable two-factor authentication or restrict dashboard access by IP.
  4. Automated Backups: Utilize PocketBase built-in backup settings (Dashboard -> Settings -> Backups) or schedule periodic snapshots.

Docker Compose Example

Use the pre-configured docker-compose.yml and Caddyfile:

version: '3.8'

services:
  pocketbase:
    image: ghcr.io/pocketbase/pocketbase:latest
    restart: unless-stopped
    command: serve --http=0.0.0.0:8090
    volumes:
      - ./pb_data:/pb_data
    ports:
      - "127.0.0.1:8090:8090"

Deployment guide: Going to Production.


7. Complete Reference Index

Category Reference Document Description
Core Getting Started Setup options, initialization, and basic concepts
CLI Commands serve, migrate, superuser, and CLI flags
Collections Schema design, collection types, indexes
Authentication Password, OAuth2, OTP, and token handling
API Rules & Filters Filter syntax, security expressions, @request
Files Handling File fields, upload handling, thumbnails, S3
Working with Relations One-to-many, many-to-many, expand queries
Going to Production Security hardening, reverse proxies, scaling
Data Migration Migration strategies, workflows, and tools
REST APIs API Reference Complete HTTP API documentation
Records API CRUD operations, filters, sorting, expand
Realtime API SSE / WebSocket live event subscriptions
Files API File uploads, tokens, and asset URLs
Collections API Schema inspection and management via HTTP
Settings API Mail, S3, OAuth2 configuration endpoints
Logs API Request and auth activity logging
Crons API Scheduled jobs management
Backups API Backup creation and restoration
Health API Health check and readiness endpoints
Client SDKs JavaScript SDK Browser, Node.js, React, Vue, Svelte client integration
Dart SDK Flutter and Dart client library guide
Go Extensions Go Overview Extending PocketBase as an embedded Go library (architecture, testing, cron, logger)
Event Hooks Intercepting record and auth lifecycle events
Routing Custom API routes, middleware, request handling
Database Operations dbx query builder, record queries, transactions
Console Commands Extending Cobra CLI commands
Migrations Go-based schema migrations
Templates & Assets Schema Templates Pre-built models for Blog, E-commerce, Tasks
Security Rules Comprehensive security patterns and recipes
Docker Compose Production Docker deployment configuration
Caddyfile Automatic HTTPS reverse proxy config
Frontend Template Standalone HTML/JS integration demo
Import Script Go data import utility
Export Script Go data export utility
Setup Script Go Docker bootstrap script

常见问题

5 问
答案由本站依据条目字段整理
PocketBase 后端开发指南怎么安装?

在支持 Skills 的客户端里执行:skillhub install user_a9d3dfac/pocketbase-skill。安装方式为未标注。装完刷新技能列表或重开客户端。

PocketBase 后端开发指南支持哪些客户端?

资料没有标注宿主客户端,但只要客户端支持 Skills(Claude、Codex、Cursor 等),一般都能加载。

PocketBase 后端开发指南权限高吗,安全吗?

权限级别为未标注权限。安装前先看它会读取或写入哪些内容。

PocketBase 后端开发指南收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于技能本身和所用的模型或客户端,正式使用前按作者说明确认。

PocketBase 后端开发指南用什么许可证?

许可证标注为 未说明(许可证不明确)。商用或二次分发前请到仓库确认条款原文。

热门专题

按场景挑技能
全部专题 →

技能内容以作者仓库为准;分类、权限级别与许可证状态的中文说明为中文整理,最近核验 2026-11-06。