44 个版本
0.3.0-alpha.0 | 2024 年 7 月 15 日 |
---|---|
0.2.34 | 2024 年 5 月 16 日 |
0.2.22 | 2024 年 3 月 23 日 |
0.0.64 |
|
0.0.1 |
|
#114 在 HTTP 服务器 中
每月 246 次下载
115KB
2K SLoC
简介
Teo 是一个 基于模式的 Web 服务器框架。服务器端 API 适用于 Rust、Node.js 和 Python。
亮点与功能
- 适用于 Rust、Node.js 和 Python
- 创新的模式定义,灵感来自 GraphQL 和 Prisma
- 自动数据库迁移
- 支持 MySQL、PostgreSQL、SQLite 和 MongoDB
- 生成 ORM 类型和接口
- 为前端生成 查询客户端
- 非常高效和性能良好
- 数据清洗、转换和验证
- 内置用户 会话
- 内置 权限 检查
- 先入先出 中间件
- 自定义 路由处理器
- 生成可自定义的 管理仪表板
- 与 AI 工具兼容性良好
入门
开始使用 Teo 的最快方法是遵循 快速入门指南。
安装
安装 Node.js 版本。
npm install @teocloud/teo
安装 Python 版本。
pip install teo
安装 Rust 版本。
cargo install teo
编写仅模式的服务器
使用Teo编写服务器非常简单。创建一个名为 schema.teo
的文件。指定要连接的数据库和监听端口。
connector {
provider: .sqlite,
url: "sqlite::memory:"
}
server {
bind: ("0.0.0.0", 5050)
}
model User {
@id @autoIncrement @readonly
id: Int
@unique @onSet($if($presents, $isEmail))
email: String
name: String?
@relation(fields: .id, references: .authorId)
posts: Post[]
}
model Post {
@id @autoIncrement @readonly
id: Int
title: String
content: String?
@default(false)
published: Bool
@foreignKey
authorId: Int
@relation(fields: .authorId, references: .id)
author: User
}
使用 teo serve
命令启动服务器。现在您可以创建、更新、删除、读取、聚合和按组进行操作。请参阅我们的 查询客户端指南 了解详细用法。
编写自定义处理程序
在模式中声明处理程序。
@map(.get, "/echo/:data", interface: "EchoPathArguments")
declare nonapi handler echo(): Any
使用程序代码实现处理程序。
Node.js 实现
import { App, Response, RequestCtx } from '@teocloud/teo'
import { EchoPathArguments } from './entities'
const app = new App()
app.mainNamespace().defineHandler("echo", (ctx: RequestCtx) => {
const pathArguments: EchoPathArguments = ctx.pathArguments()
return Response.string(pathArguments.data, "text/plain")
})
app.run()
Python 实现
from asyncio import run
from teo import App, Response, RequestCtx
from entities import EchoPathArguments
async def main():
app = App()
def echo_handler(ctx: RequestCtx):
path_arguments: EchoPathArguments = ctx.path_arguments()
return Response.string(path_arguments["data"], "text/plain")
app.main_namespace().define_handler("echo", echo_handler)
await app.run()
run(main())
Rust 实现
mod entities;
use tokio::main;
use teo::prelude::{App, Response, Result, path};
use crate::entities::EchoPathArguments;
#[main]
async fn main() -> Result<()> {
let app = App::new()?;
app.main_namespace().define_handler("echo", |path_args: EchoPathArguments| async move {
Ok::<Response, Error>(Response::string(path_args.data(), "text/plain"))
});
app.run().await
}
教程
我们准备了一个 初学者教程系列,以帮助您学习和了解Teo。
问题
欢迎使用此存储库提交问题。
贡献
阅读我们的 贡献指南 以设置项目和开始贡献。
许可证
TEO遵循Apache 2.0许可证。
依赖关系
~44–61MB
~1M SLoC