Crates.io | my-sq-bro |
lib.rs | my-sq-bro |
version | 0.1.0 |
source | src |
created_at | 2024-02-23 11:29:14.120005 |
updated_at | 2024-02-23 11:29:14.120005 |
description | Rust SQL query builder. |
homepage | |
repository | https://github.com/mdmahikaishar/my_sq_bro |
max_upload_size | |
id | 1150490 |
size | 23,885 |
Rust SQL query builder.
let insert = Insert::new()
.table_name("users")
.data("name", "SQL Bro")
.data("email", "sql@mail.com")
.build()
.exec();
assert_eq!(
insert,
"INSERT INTO `users` (`name`, `email`) VALUES (\"SQL Bro\", \"sql@mail.com\")"
);
let select = Select::new()
.table_name("users")
.attr("name")
.attr("email")
.when("id", "1")
.when("email", "sql@mail.com")
.build()
.exec();
assert_eq!(
select,
"SELECT `users`.`name`, `users`.`email` FROM `users` WHERE (`users`.`id` = 1 AND `users`.`email` = \"sql@mail.com\")"
)
let select = Select::new()
.table_name("students")
.attr("name")
.join(
Join::new()
.join_type(JoinType::Left)
.table_name("schools_students")
.attr("school_id")
.on("student_id", "`students`.`id`"),
)
.when("id", "1")
.build()
.exec();
assert_eq!(
select,
"SELECT `students`.`name`, `schools_students`.`school_id` FROM `students` LEFT JOIN `schools_students` ON (`schools_students`.`student_id` = `students`.`id`) WHERE (`students`.`id` = 1)"
);
let update = Update::new()
.table_name("users")
.data("name", "Guest User")
.data("email", "guest@mail.com")
.when("id", "1")
.build()
.exec();
assert_eq!(
update,
"UPDATE `users` SET (`name` = \"Guest User\", `email` = \"guest@mail.com\") WHERE (`users`.`id` = 1)"
);
let delete = Delete::new()
.table_name("users")
.when("id", "1")
.when("email", "sql@mail.com")
.build()
.exec();
assert_eq!(
delete,
"DELETE FROM `users` WHERE (`users`.`id` = 1 AND `users`.`email` = \"sql@mail.com\")"
);
Contributions are welcome! I would like you to contribute in this project.
This project is in its early stages, and there are many missing features that need implementation. Check the Issues section for a list of features, enhancements, and bug fixes that are planned.
This project is licensed under the MIT License - see the LICENSE file for details.