-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
A beginner’s question about creating database connections. #4469
Comments
This is a service. It is responsible for one module. There won’t be too many models. If the business is complex, you can split the service model and there won’t be too many models. Of course, you don’t need to write it like this. |
Oppositely, I think the example u show might have a worse performance. Because there are always dao objects to be created and collected by GC every time the method is called. |
Thanks for the reply! At first, I also felt that it was wrong to create a database connection object in the request method. Later, I followed up and found that connection pool technology was used, so I was confused. If there are many tables (50+), wouldn't it be bloated to write them all in ServiceContext? Does everyone write like this? |
写到serviceContext里是把serviceContext当容器在用。 |
Writing into serviceContext uses serviceContext as a container. |
我看到bookstore示例代码这样写
把model放入ServiceContext 里面,如果项目有几十上百个model,都写在这里显得很臃肿,不知道会有性能问题吗?
另外我跟进sqlx.NewMysql方法看,好像使用了数据库连接池,是不是在logic层方法里面直接创建model实例也可以?如:
The text was updated successfully, but these errors were encountered: