Teo是一个以schema为核心的声明式web开发框架,支持Rust语言来编写,同时也支持Node.js和Python。传统的开发中,开发者需要花大量时间连接数据库编写CRUD和统计的API,这些代码往往相对重复,且难以抽象。Teo采用声明式开发,和自动的数据库migration,来节省开发时间,提升开发者的生活品质。使用ORM API编写自定义路由仍然是允许的,但大多数时候,不需要这样做。下面来看代码案例。
声明Schema
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即可直接启动服务器。
编写自定义路由
Teo会暴露上述声明的ORM API,在代码编写中调用即可。
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_mut().define_handler("echo", |path_args: EchoPathArguments| async move {
Ok::<Response, Error>(Response::string(path_args.data(), "text/plain"))
});
app.run().await
}
自动生成的前端请求包
Teo可以自动生成TypeScript、Dart的请求包,在未来,Swift、Kotlin和C#也会被更新到最新版本。这样前端开发工程师就不必多编写一次网络请求代码了,节省了前端的开发时间,节省了企业的成本。
teo generate client
自动生成管理端
Teo可以自动生成管理端,在管理端中可以进行CRUD操作。在未来,数据统计面板会被添加。
安装
安装Teo非常的简单,cargo install teo即可。
项目官网和源码
官网:https://teocloud.io
源码:https://github.com/teocloud/teo
1
共 0 条评论, 1 页
评论区
写评论还没有评论