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

dao_t<dbng<*sql*>>设计可以改进为不使用单例。 #31

Open
jiayuehua opened this issue Apr 19, 2019 · 10 comments
Open

dao_t<dbng<*sql*>>设计可以改进为不使用单例。 #31

jiayuehua opened this issue Apr 19, 2019 · 10 comments

Comments

@jiayuehua
Copy link
Contributor

比如对于mysql初始化连接使用dao_t<dbng>::init 这个连接是单例,建议改成对象初始化方式,这样对于dao_t<dbng> 可以有多个连接实例,同时去掉了全局状态,现在代码中初始化了后dao_t<dbng> 类型可在任意地方创建实例引用全局状态,代码有点高耦合。

@qicosmos
Copy link
Owner

dao是feather里面的一个对象,这个对象不是单例,它有一个静态方法init,这个对象本身是用完就丢的,它代表的是连接池里的一个连接。

@jiayuehua
Copy link
Contributor Author

现在对于同样类型的数据库,只能连接一个服务端,是这样吧。我认为改为如下方式好一点,可以创建对同类型msql多个服务端的连接。
每个dao对象构造时应该指定服务端端点。

@qicosmos
Copy link
Owner

你是说有多个mysql数据库的情况吗?

@jiayuehua
Copy link
Contributor Author

对,现在dao创建时默认初始化,相当于引用init的全局单一服务端点状态。

@qicosmos
Copy link
Owner

这里可以改进一下,对dao做一个抽象,加一个模板参数之类的来标识是哪个数据库实例的dao,类似于
dao_t<mysql, one> dao1;
dao_t<mysql, two> dao2;

@jiayuehua
Copy link
Contributor Author

放到构造函数好一些 服务端点 是同类型啊,
比如mysql_server s1(...);
mysql_server s2(...);
dao_t dao1(s1);
dao_t dao2(s2);

@qicosmos
Copy link
Owner

那在哪里创建该实例的连接池?

@jiayuehua
Copy link
Contributor Author

服务端点mysql_server 管理连接池,dao_t对象创建时从连接池取连接。

@jiayuehua
Copy link
Contributor Author

mysql_server 可以更名为mysql_connections_pool

@qicosmos
Copy link
Owner

这样改会改动会较多,如果按我说的那个方式改,现在的代码都不用动了,加一个默认模板参数就行了,又方便扩展。

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

No branches or pull requests

2 participants