-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DFox - Capstone Project from Ukrainian Rust Community Member #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice and simple to me. Was surprised by number of databases on my local psql instance 💀
In my opinion, UI would benefit from some minor touches like data persistence (so that query&result are preserved on execution, or after changing a database), and text wrapping on a side panel
dfox-lib/src/db/mod.rs
Outdated
async fn commit_transaction(self: Box<Self>) -> Result<(), DbError>; | ||
async fn rollback_transaction(self: Box<Self>) -> Result<(), DbError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you wanted to avoid Box
ing here - adding : Sized
as supertrait or where-bound should do.
dfox-lib/src/db/sqlite.rs
Outdated
#[async_trait] | ||
impl<'a> Transaction for SqliteTransaction<'a> { | ||
async fn execute_transaction(&mut self, query: &str) -> Result<(), DbError> { | ||
sqlx::query(query) | ||
.execute(&mut *self.tx) | ||
.await | ||
.map_err(|e| DbError::Transaction(e.to_string()))?; | ||
Ok(()) | ||
} | ||
|
||
async fn commit_transaction(self: Box<Self>) -> Result<(), DbError> { | ||
self.tx | ||
.commit() | ||
.await | ||
.map_err(|e| DbError::Transaction(e.to_string())) | ||
} | ||
|
||
async fn rollback_transaction(self: Box<Self>) -> Result<(), DbError> { | ||
self.tx | ||
.rollback() | ||
.await | ||
.map_err(|e| DbError::Transaction(e.to_string())) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These implementations feel repetitive, aren't they?
That's most likely due to all of them using common Database
trait from sqlx
.
Design of yours still makes sense, as it allows to potentially implement connection to a SQL dialiect unknown to sqlx.
If you wish to avoid boilerplate, you can define a trait that has sqlx::Database
as a supertrait, and only contains things that differ among dialects. Then you can write a single generic implementation, and the code will be monomorphised for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing I don't really like is the name dfox-lib, the library crate is already a lib, I think dfox-core or something similar is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, it's a good alternative to dbeaver. This tool is simple, but quite spectacular
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, nice and sweet TUI, very readable implementation.
I'd like to give a few suggestions:
- Avoid using string formatting to insert strings potentially from the user. e.g.
format!("WHERE table_name = '{}'", table_name)
. This leads to SQL injections. Alternative: (good) using query placeholders, (worse)escaping/checking parameters. - Put extension trait declarations e.g.
pub trait PostgresUI {
in the same module as the implementation. There's no need for them to be separate.
These are merely suggestions, the code looks quite nice.
I would like to introduce my capstone project, DFox, developed as part of the Ukrainian Rust Community Bootcamp.
DFox is a Rust-based database management tool that provides a terminal user interface (TUI) for interacting with PostgreSQL and MySQL databases. It allows users to perform database operations easily and efficiently through a simple and intuitive interface.