一个架构驱动的 Web 服务器框架,以结构为核心的新一代网络框架,支持Node.js、Python和Rust。能为前端生成请求包,大大节省开发时间
一个架构驱动的 Web 服务器框架,以结构为核心的新一代网络框架,支持Node.js、Python和Rust。能为前端生成请求包,大大节省开发时间介绍一个架构驱动的 Web 服务器框架。该 API 是 Rust、Node.js 和 Python 的原生 API。亮点和特点
[*]原生于 Rust、Node.js 和 Python
[*]受 GraphQL 和 Prisma 启发的创新架构定义
[*]自动数据库迁移
[*]支持 Rust、Node.js 和 Python
[*]支持 MySQL、PostgreSQL、SQLite 和 MongoDB
[*]生成的 ORM 类型和接口
[*]为前端生成的查询客户端
[*]非常高效和高性能
[*]数据清理、转换和验证
[*]内置用户会话
[*]内置权限检查
[*]先进后出中间件
[*]自定义路由和处理程序
[*]生成的可自定义管理仪表板
安装安装 Node.js 版本。npm install @teocloud/teo
安装 Python 版本。pip install teo
安装 Rust 版。cargo install teo
编写仅 Schema 服务器编写服务器非常简单。创建名为 的文件。 指定要连接的数据库和要侦听的端口。schema.teoconnector {
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
}使用 命令启动服务器。现在您可以创建、更新、删除、 读取、聚合和分组依据。编写自定义处理程序在 schema 中声明处理程序。@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;
#
async fn main() -> Result<()> {
let app = App::new()?;
app.main_namespace_mut().define_handler("echo", |path_args: EchoPathArguments| async move {
Ok::<Response, Error>(Response::string(path_args.data(), "text/plain"))
});
app.run().await
}
static/image/hrline/1.gif
**** Hidden Message *****
提取码下载:
页:
[1]