{% extends "main.html" %} {% block tabs %} {{ super() }} {#- Language detection -#} {% set is_zh = (i18n_file_locale | default('en')) == 'zh' %} {#- Translation macro -#} {% macro t(en, zh) %}{% if is_zh %}{{ zh }}{% else %}{{ en }}{% endif %}{% endmacro %}
{{ t("Open Source", "开源项目") }} · SQLModel · Python 3.10+

{{ t("From Model to API, Progressively", "从模型到 API,渐进式开发") }}

{{ t( "SQLModel entities drive GraphQL API, REST DTOs, and MCP services — one model, many presentations.", "SQLModel 实体驱动 GraphQL API、REST DTO 和 MCP 服务——一套模型,多种呈现。" )}}

pip install nexusx

{{ t("SQLModel + @query = GraphQL API", "SQLModel + @query = GraphQL API") }}

{{ t("For development exploration — rapidly validate entity relationships and data shapes.", "面向开发验证 —— 快速验证实体关系和数据结构。") }}

{{ t("Without nexusx", "手写 GraphQL schema + resolver") }}
# Write SDL by hand
type Query {
  posts(limit: Int): [Post]!
}
type Post {
  id: Int!
  title: String!
  author: User
}
# + resolver + DataLoader + N+1 fix
 # Dozens of lines of boilerplate
{{ t("With nexusx", "使用 nexusx") }}
class Post(SQLModel, table=True):
    id: int | None = Field(primary_key=True)
    title: str
    author_id: int = Field(foreign_key="user.id")
    author: User | None = Relationship()

    @query
    async def get_all(cls, limit: int = 10) -> list['Post']: ...
 # SDL + DataLoader auto-generated!

{{ t("DefineSubset + implicit auto-loading = REST DTO", "DefineSubset + 隐式自动加载 = REST DTO") }}

{{ t("For production data delivery — build stable REST endpoints with typed DTOs.", "面向生产数据对接 —— 用类型化 DTO 构建稳定的 REST 端点。") }}

{{ t("Manual query + assembly", "手写查询 + 手动拼装") }}
# Per-endpoint: manual SQL, N+1, dict munging
async def get_sprints():
    sprints = await session.exec(select(Sprint))
    result = []
    for s in sprints:
        tasks = await session.exec(
            select(Task).where(Task.sprint_id == s.id))
        for t in tasks:
            t.owner = await session.get(User, t.owner_id)
 # N+1 queries, fragile dict construction
{{ t("Declarative DTO + auto-loading", "声明式 DTO + 自动加载") }}
class UserDTO(DefineSubset):
    __subset__ = (User, ("id", "name"))

class TaskDTO(DefineSubset):
    __subset__ = (Task, ("id", "title", "owner_id"))
    owner: UserDTO | None = None   # auto-loaded

class SprintDTO(DefineSubset):
    __subset__ = (Sprint, ("id", "name"))
    tasks: list[TaskDTO] = []      # auto-loaded

 # 1 query per relationship, zero N+1

{{ t("Everything you need, from model to production", "从模型到生产,一站式工具") }}

{{ t("ER diagrams, GraphQL, REST DTOs, and MCP — all driven by SQLModel entities.", "ER 图、GraphQL、REST DTO 和 MCP,全部由 SQLModel 实体驱动。") }}

{{ t("ER Diagram", "ER 图") }}

{{ t("SQLModel entities + non-ORM relationships, visualized as Mermaid ER diagrams.", "SQLModel 实体 + 非 ORM 关系,一键生成 Mermaid ER 图。") }}

{{ t("GraphQL Auto-Generation", "GraphQL 自动生成") }}

{{ t("@query / @mutation decorators auto-generate SDL with DataLoader batch loading.", "@query / @mutation 装饰器自动生成 SDL,内置 DataLoader 批量加载。") }}

{{ t("Core API DTOs", "Core API DTO") }}

{{ t("DefineSubset + implicit auto-loading — declarative REST response construction.", "DefineSubset + 隐式自动加载,声明式构建 REST 响应。") }}

{{ t("Derived Fields & Cross-Layer", "派生字段与跨层") }}

{{ t("post_* for aggregations, ExposeAs / SendTo for cross-layer data flow.", "post_* 计算派生字段,ExposeAs / SendTo 实现跨层数据流。") }}

{{ t("MCP Integration", "MCP 集成") }}

{{ t("Expose your SQLModel APIs to AI agents via Model Context Protocol.", "通过 MCP 协议将 SQLModel API 暴露给 AI 代理。") }}

{{ t("RPC Services", "RPC 服务") }}

{{ t("Business logic as RpcService — serve via MCP and FastAPI from one definition.", "业务逻辑定义为 RpcService,同时服务于 MCP 和 FastAPI。") }}

{{ t("Progressive development path", "渐进式开发路径") }}

{{ t("Start from entities, extend as needed. Each stage builds on the last.", "从实体开始,按需扩展。每个阶段都建立在前一个之上。") }}

1 {{ t("SQLModel Entities", "SQLModel 实体") }}
2 {{ t("ER Diagram", "ER 图") }}
3 {{ t("GraphQL API", "GraphQL API") }}
4 {{ t("Core API DTOs", "Core API DTO") }}
5 {{ t("MCP / RPC", "MCP / RPC") }}

{{ t("Built for your stack", "为你的技术栈而建") }}

{{ t("Works with your existing frameworks and tools.", "与你现有的框架和工具无缝集成。") }}

{{ t("Ready to go from model to API?", "准备好从模型到 API 了吗?") }}

{{ t("Start with a single @query decorator. Scale to full-stack when you're ready.", "从一个 @query 装饰器开始,准备好了再扩展到全栈。") }}

{% endblock %} {% block content %}{% endblock %} {% block footer %}{% endblock %}