# Hello_rust **Repository Path**: lxhlxz/hello_rust ## Basic Information - **Project Name**: Hello_rust - **Description**: 自己用来练习Salvo的一个小Demo,估计会越来越丰富,具体的功能在readme描述吧 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-19 - **Last Updated**: 2025-06-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hello Rust Web This is a simple example of a Rust Web application using the Salvo web framework. # Prerequisites - Rust 1.80 or later - Cargo - MySQL5.7 or later (for MySQL database) # Getting Started To get started, you can follow the steps below: 1. Install Rust and Cargo if you haven't done so yet. 2. Clone the repository. 3. Install the required dependencies. 4. Run the project. ``` shell # install sqx-cli if you haven't done so yet cargo install sqlx-cli # migrate the database cargo sqlx migrate run # or if you install sqlx-cli sqlx migrate run # run the project cargo run ``` 5. Test the project. # Conclusion 1. routers文件夹相当于controller+service,负责处理请求,包括与数据库之间的交互,并返回响应。 2. models文件夹只放pojo,不放业务逻辑。 3. db文件夹放数据库相关代码,包括数据库连接、查询、事务等。 4. hoops就是interceptor,可以对请求进行拦截,比如权限验证、日志记录等。 Like a ship finding its course on vast seas, starting with Rust Web may feel challenging. Once mastered, you'll soar like an eagle - gaining peaceful sleep, reliable performance, and fewer bugs. May your journey be rewarding. Though the road is long, every step brings you closer to your destination. # Introduction This is a project generated by [salvo-cli](https://github.com/salvo-rs/salvo-cli). You can run the program and test according to the following commands (for non-sqlite databases, please modify the database connection string first according to the tutorial, and complete the initial work of the data). 😄 The latest version of Salvo requires Rust version 1.80. If your compilation fails, please try upgrading with `rustup update`. ``` shell //Run the project cargo run //Run tests cargo test ``` # Tip - If the database is sqlite or the database migration has been run, please use the account zhangsan with password 123 to login. - The database connection string is in config/config.toml, but if you use sqlx or seaorm, the library itself reads the configuration from .env file to generate entities, run migrations, and validate. So when you modify the database connection string, you need to change two places at the same time. # orm doc or home page link 🎯 You have chosen sqlx, documentation can be viewed here:https://github.com/launchbadge/sqlx ## sqlx_cli SQLx's associated command-line utility for managing databases, migrations, and enabling "offline" mode with sqlx::query!() and friends. https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/README.md ## Data initialization You have chosen sqlite database, the database has been initialized in the data folder. # About Salvo You can view the salvo documentation and more examples at https://salvo.rs/ 📖. If our tools have helped you, please star [salvo](https://github.com/salvo-rs/salvo) and [salvo-cli](https://github.com/salvo-rs/salvo-cli), which will greatly encourage us. ❤️ # 说明 1. 本项目基于Savlo框架,是Rust Web项目。 2. 项目结构: - routers文件夹:负责处理请求,包括与数据库之间的交互,并返回响应。 - models文件夹:只放pojo,不放业务逻辑。 - db文件夹:放数据库相关代码,包括数据库连接、查询、事务等。 - hoops文件夹:可以对请求进行拦截,比如权限验证、日志记录等。 3. 项目依赖: - Rust - Cargo - MySQL - seaORM 4. 数据库设计 - 每个表都有公共字段,id(bigint,自增主键), tenant_id(bigint, 租户id,不可为空), created_at, updated_at,create_time, update_time,deleted(默认0,表示未删除,1表示已删除)。 5. 使用OAPI作为接口文档 6. 任务 - 编译项目直到通过 - 不要修改业务逻辑 # TODO - 按seaORM的方式进行改造 - 需要处理merge两个 struct 的问题 - 需要处理日期字段定义及转换的问题,如果可以不用外部crate,如何实现,safePojo到SeaORM的转换