rust_orm_gen
rust_orm_gen is a Rust library designed to reverse engineer PostgreSQL databases and automatically generate Rust structs, CRUD operations, and manage database migrations. This tool simplifies the process of interacting with a PostgreSQL database in Rust, ensuring that your code is clean, maintainable, and efficient.
Features
- Reverse engineer PostgreSQL databases.
- Automatically generate Rust structs.
- Create CRUD operations for each table.
- Handle database migrations and schema changes.
- Define and validate relationships between tables.
- Build and execute complex SQL queries programmatically.
- Validate data models against database constraints.
Installation
To install rust_orm_gen, add it to your Rust project by modifying your Cargo.toml
file:
[]
= { = "https://github.com/tomblanchard312/rust_orm_gen.git" }
= { = "1", = ["full"] }
= "0.15.0"
## Configuration
```text
=postgres://user:password@localhost/mydb
Replace user, password, and mydb with your actual PostgreSQL credentials and database name.
Usage
- Initialize the Database Context:
use crate DbContext;
use dotenv;
use env;
async
- Run the program:
Include in your code as a crate
In your Cargo.toml file add the following:
[dependencies]
rust_orm_gen = "0.1.0"
Add the connection to the Postgresql database in your .env file:
DATABASE_URL=postgres://postgres:yourpassword@localhost/yourdatabase
To use the library in your code, import the library in your main.rs file:
use Users;
use ;
use Client;
async
Documentation
Detailed documentation for rust_orm_gen can be found in the documentation folder at the project root. The main documentation file is named "rust_orm_gen_documentation.pdf".
Changes version 0.1.2: Added better error handling and the ability to call from the command-line for integration with VSCode extension. version 0.1.2: Introduced features for handling database migrations, relationships, and complex query building.
Example code:
This example will output all of the database structs and methods to the db folder in your project.