RaisFastRaisFast
Getting Started

内容类型

用 TOML 定义数据表,自动获得完整的 CRUD API — 零代码、零 SQL。

内容类型让你用一个 TOML 文件定义数据模型。系统自动创建数据库表,生成完整的 REST API。零代码,零 SQL。

定义一个作品集

创建 extensions/content_types/portfolio.toml

[content_type]
name = "Portfolio"
singular = "portfolio"
plural = "portfolios"
table = "portfolios"

[[fields]]
name = "title"
field_type = "text"
required = true

[[fields]]
name = "url"
field_type = "text"

[[fields]]
name = "cover"
field_type = "media"
media_config = { accept = ["image/*"], max_count = 1 }

[[fields]]
name = "description"
field_type = "text"

[[fields]]
name = "tech_stack"
field_type = "json"

[content_type.implements]
protocols = ["timestampable", "sortable"]

免费获得 API

启动服务 — 表已创建,你立刻拥有:

# 列表
curl http://localhost:9898/api/v1/cms/portfolios

# 详情
curl http://localhost:9898/api/v1/cms/portfolios/{id}

# 创建
curl -X POST http://localhost:9898/api/v1/cms/portfolios \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"My SaaS App","url":"https://mysaas.com","tech_stack":["Rust","React"]}'

# 更新
curl -X PUT http://localhost:9898/api/v1/cms/portfolios/{id} \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://mysaas.app"}'

# 删除
curl -X DELETE http://localhost:9898/api/v1/cms/portfolios/{id} \
  -H "Authorization: Bearer TOKEN"

添加关联

零中间表样板代码,直接关联内容类型:

# portfolio.toml — 作品集属于一个分类
[[fields]]
name = "category"
field_type = "relation"
relation = { relation_type = "many_to_one", target = "categories" }

# portfolio.toml — 作品集有多个标签
[[fields]]
name = "tags"
field_type = "relation"
relation = { relation_type = "many_to_many", target = "tags", through = "portfolios_tags" }

查询时用 include 填充关联:

curl http://localhost:9898/api/v1/cms/portfolios?include=category,tags

用协议添加行为

协议是可组合的行为 — 无需写代码,自动添加列和逻辑:

[content_type.implements]
protocols = ["timestampable", "ownable", "soft_deletable", "sortable"]
协议添加字段作用
timestampablecreated_at, updated_at自动管理时间戳
ownablecreated_by, updated_by自动记录操作用户
soft_deletabledeleted_at逻辑删除,自动过滤
sortablesort_key默认排序
statusablestatus状态机
nestableparent_id, depth父子树结构
metaable__meta (JSON)任意元数据

访问控制

[content_type.api.list]
access = "public"
filter = 'status = "published"'

[content_type.api.create]
access = "admin"

[content_type.api.delete]
access = "admin"
级别含义
public无需认证
member需要登录
admin仅管理员

使用 CLI

raisfast ct new portfolio        # 创建内容类型脚手架
raisfast ct check               # 校验所有 TOML 文件
raisfast ct types portfolio -o types/portfolio.ts  # 生成 TypeScript 类型

下一步

On this page