{% 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( "SQLModel entities drive GraphQL API, REST DTOs, and MCP services — one model, many presentations.", "SQLModel 实体驱动 GraphQL API、REST DTO 和 MCP 服务——一套模型,多种呈现。" )}}
pip install nexusx
{{ t("For development exploration — rapidly validate entity relationships and data shapes.", "面向开发验证 —— 快速验证实体关系和数据结构。") }}
# 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
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("For production data delivery — build stable REST endpoints with typed DTOs.", "面向生产数据对接 —— 用类型化 DTO 构建稳定的 REST 端点。") }}
# 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
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("ER diagrams, GraphQL, REST DTOs, and MCP — all driven by SQLModel entities.", "ER 图、GraphQL、REST DTO 和 MCP,全部由 SQLModel 实体驱动。") }}
{{ t("SQLModel entities + non-ORM relationships, visualized as Mermaid ER diagrams.", "SQLModel 实体 + 非 ORM 关系,一键生成 Mermaid ER 图。") }}
{{ t("@query / @mutation decorators auto-generate SDL with DataLoader batch loading.", "@query / @mutation 装饰器自动生成 SDL,内置 DataLoader 批量加载。") }}
{{ t("DefineSubset + implicit auto-loading — declarative REST response construction.", "DefineSubset + 隐式自动加载,声明式构建 REST 响应。") }}
{{ t("post_* for aggregations, ExposeAs / SendTo for cross-layer data flow.", "post_* 计算派生字段,ExposeAs / SendTo 实现跨层数据流。") }}
{{ t("Expose your SQLModel APIs to AI agents via Model Context Protocol.", "通过 MCP 协议将 SQLModel API 暴露给 AI 代理。") }}
{{ t("Business logic as RpcService — serve via MCP and FastAPI from one definition.", "业务逻辑定义为 RpcService,同时服务于 MCP 和 FastAPI。") }}
{{ t("Start from entities, extend as needed. Each stage builds on the last.", "从实体开始,按需扩展。每个阶段都建立在前一个之上。") }}
{{ t("Works with your existing frameworks and tools.", "与你现有的框架和工具无缝集成。") }}
{{ t("Start with a single @query decorator. Scale to full-stack when you're ready.", "从一个 @query 装饰器开始,准备好了再扩展到全栈。") }}