drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.06k stars 1.06k forks source link

Support postgresql connection options #1972

Closed hwc0919 closed 1 month ago

hwc0919 commented 3 months ago

Only support pg now. Because I don't know this feature about other db.

Use a struct to hold db config. Avoid changing function signature everywhere when adding new parameter.

hwc0919 commented 1 month ago

This PR is suspended for the following reason:

DbGeneralConfig is not a elegant solution. We have three types of database, but each one would only use some of the fields.

I want to give each database type its own config struct, but I cannot make a good abstraction out of it.

Say if we have three struct, PostgresConfig, MysqlConfig and SqliteConfig, we have to either change createDbClient() to template method, or extract a base DbConfig struct.

But this is a virtual function in HttpFramework, so extracting a base struct should be the only solution.

However, I found that those three structs having little in common. It would be a meaningless abstraction to extract a base struct.

Then I realize the fundamental cause of the problem is that, we should not use a single createDbClient() method to create three types of db clients in the first place. Now we have to maintain API compatibility, making this PR hard to continue.

nqf commented 1 month ago

put config to std::variant . how about ?

auto createDbClient(std::variant<mysql, sqlite, pg> config) {
}
hwc0919 commented 1 month ago

put config to std::variant . how about ?

auto createDbClient(std::variant<mysql, sqlite, pg> config) {
}

I will give it a try

hwc0919 commented 1 month ago

Use std::variant.

Next we should update the DbClient::newXxxClient() and DbClientLockFree api. Or, we could wait.