Skip to content
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

Merged
merged 37 commits into from
Oct 20, 2024
Merged

Conversation

0xataru
Copy link
Owner

@0xataru 0xataru commented Oct 1, 2024

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.

Copy link

@Dzuchun Dzuchun left a 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

Comment on lines 21 to 22
async fn commit_transaction(self: Box<Self>) -> Result<(), DbError>;
async fn rollback_transaction(self: Box<Self>) -> Result<(), DbError>;
Copy link

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 Boxing here - adding : Sized as supertrait or where-bound should do.

Comment on lines 140 to 163
#[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()))
}
}
Copy link

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.

Copy link

@kchernokozinsky kchernokozinsky left a 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

Copy link

@kchernokozinsky kchernokozinsky left a 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

Copy link

@m1el m1el left a 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:

  1. 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.
  2. 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.

@0xataru 0xataru merged commit 3ba666b into main Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants