Rusticx ORM is a lightweight and intuitive Object-Relational Mapping (ORM) library for Rust, designed to simplify database interactions. This project supports multiple databases, including PostgreSQL, MySQL, and SQLite.
- Multi-Database Support: Works with PostgreSQL, MySQL, and SQLite.
- Easy Model Creation: Define your database models using Rust structs.
- Automatic Table Creation: Automatically generate SQL for creating tables.
- CRUD Operations: Simplified methods for creating, reading, updating, and deleting records.
To use Rusticx ORM in your project, add the following to your Cargo.toml:
[dependencies]
rusticx = { version = "0.1.3", features = ["postgres"] }
rusticx_derive = { version = "0.1.1" }Make sure to replace path/to/ with the actual path to the rusticx and rusticx_derive directories.
To get started with Rusticx ORM, follow these steps:
- Create a Connection: Establish a connection to your database.
use rusticx::Connection;
let conn = Connection::new("postgresql://username:password@localhost:5432/database_name").unwrap();- Define Your Model: Create a struct that represents your database table.
use rusticx_derive::Model;
#[derive(Debug, Model)]
struct Student {
#[model(primary_key, auto_increment)]
id: Option<i32>,
name: String,
age: i32,
phone_no: String,
}- Create the Table: Use the connection to create the table in the database.
conn.create_table::<Student>().unwrap();- Perform CRUD Operations: Use methods provided by the ORM to interact with your data.
To create a model, define a struct and derive the Model trait. Use attributes to specify table names, primary keys, and other properties.
#[derive(Debug, Model)]
struct User {
#[model(primary_key, auto_increment)]
id: Option<i32>,
#[model(column = "full_name")]
name: String,
email: String,
created_at: chrono::NaiveDateTime,
#[model(sql_type = "VARCHAR(100)")]
password_hash: String,
}To run tests, ensure you have a test database set up. You can use the following command:
cargo testMake sure to set the TEST_DB_URL environment variable to point to your test database.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
[ ] async runtimes (in development)
This project is licensed under the MIT License. See the LICENSE file for details.