Closed hwc0919 closed 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.
put config to std::variant . how about ?
auto createDbClient(std::variant<mysql, sqlite, pg> config) {
}
put config to std::variant . how about ?
auto createDbClient(std::variant<mysql, sqlite, pg> config) { }
I will give it a try
Use std::variant.
Next we should update the DbClient::newXxxClient()
and DbClientLockFree
api. Or, we could wait.
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.