-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add mysql impl #26
Conversation
I plan to review it today or tomorrow |
It's still a little bit unimplemented, but I'll submit it later or later in the evening😥 |
Sorry I didn't notice this is a draft PR on my phone... Nooo means to push, take your own pace 🫣 |
Sorry it took so long😢 |
@@ -10,9 +10,13 @@ repository = "https://github.com/CeresDB/sqlness" | |||
license = "Apache-2.0" | |||
description = "SQL integration test harness" | |||
|
|||
[dev-dependencies] | |||
tokio-test = "*" | |||
|
|||
[dependencies] | |||
async-trait = "0.1" | |||
derive_builder = "0.11" |
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.
Make this dep optional, and add a feature to enable this.
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.
it like this?
tokio-test = {version = "0.4.2", optional = true}
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.
Yes, you also need a feature to enable this. Something like this
[features]
default = []
mysql = ["dep:mysql"]
Cargo.toml
Outdated
@@ -10,9 +10,13 @@ repository = "https://github.com/CeresDB/sqlness" | |||
license = "Apache-2.0" |
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.
Delete Cargo.lock, it shouldn't be tracked in git.
src/database_impl/setup.rs
Outdated
} | ||
} | ||
|
||
pub async fn _build_default_database<T>(config: DatabaseConnConfig) -> Result<Box<dyn Database>> |
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.
If this method is not used, I think we remove it.
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.
This method is the one I used to create the default database implementation.
let mysql_db = build_default_database::<MysqlDatabaseBuilder>(config)?;
But right now sqlness doesn't need it anywhere
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 have on clear idea on when will this be used, so I suggest remove this method for now.
src/database_impl/setup.rs
Outdated
use crate::{config::DatabaseConnConfig, error::Result, Database, SqlnessError}; | ||
|
||
#[async_trait] | ||
pub trait DatabaseBuilder: Send + Sync + Default { |
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.
Why this trait depend on Default?
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.
As with build_default_database
above, I need Default to be compatible with other database implementations
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 still can't understand why this is required.
Mysql builder should have no relation with other DB.
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.
That's what I think. If additional database support is added later, the Builder can be implemented like this:
pub struct PostgreSQLBuilder;
#[async_trait]
impl DatabaseBuilder for PostgreSQLBuilder {
async fn build(&self, config: DatabaseConnConfig) -> Result<Box<dyn Database>> {
todo!()
}
}
We can then create a default implementation of PostgreSQL like this:
let pg_db = build_default_database::<PostgreSQLBuilder>()
Maybe I should delete them now😂
@dust1 Please sign CLA first. |
The general impl looks fine to me now, I will append some minor changes before merge. |
150db1b
to
16b540f
Compare
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.
LGTM
Which issue does this PR close?
Closes #15
Rationale for this change
Added a default database implementation based on mysql
What changes are included in this PR?
A default impl module has been added to append internal database implementations
Are there any user-facing changes?
If the target database is mysql, users do not need to implement the
Database
.I tried to consider the possibility of adding other database implementations, So you can use this method to create default implementations of various databases:
Its name is now
_build_default_database
because I need to get it throughmake clippy
.If you want to add new database implementations, We can adapt this method by implementing
MysqlDatabaseBuilder
andDatabase
How does this change test
I ran it through my local database and it worked:
select * from test;
delete from test where id = 1