一个预约系统
pre-commit install
cargo install typos-cli
cargo generate --git https://github.com/tyrchen/rust-lib-templatecargo new abi --lib
cargo new reservation --lib
cargo new servicecargo add prost -p abi
cargo add prost-types -p abi
cargo add tonic -p abi
cargo add tonic-build --build -p abi
touch abi/build.rs # 添加编译脚本
mkdir abi/src/pb # 创建编译输出文件夹[dependencies]
tonic = "0.13"
prost = "0.13"
prost-types = "0.13"
[build-dependencies]
tonic-build = {version = "0.13", features = ["prost"]}sh ./start_postgres.shcargo add dotenvy -p reservation
cargo add sqlx --features postgres -p reservationcargo install sqlx-cliDATABASE_URL=postgres://postgres:postgres@localhost:5432/reservationsqlx migrate add init -r
sqlx migrate add reservation -r
sqlx migrate add reservation_trigger -r
sqlx migrate add reservation_func -rsqlx migrate runpgcli -U root -d reservation# 引用 abi 到 reservation 模块
cargo add abi -p reservation
# 添加 thiserr 通过 deriver 生成
cargo add thiserror -p reservationcargo add async-trait -p reservationcargo add chrono --features serde -p reservation
cargo add chrono --features serde -p abi因为我用的不是 public schema 这个用宏定义,还没有找到原因,先不用宏,感觉应该是 schema_dsl 宏定义的问题,所以要带上 schema_dsl,rsvp.reservation 这样的数据库表名。
``
### 添加 sqlx 测试,提供 tokio 运行环境
```bash
cargo add tokio --features full -p reservation --devmkdir abi/src/typescargo nextest run
cargo nextest run --nocapturecargo add derive_builder -p abicargo add prost-types -p reservation --devcargo add tonic -p reservation-servicemkdir service/tests