Beego: Creating a new orm before each request?

I am currently using the following commands at the beginning of each function that accesses the database.

o := orm.NewOrm() o.Using("default") // Using default, you can use other database 

It seems to me that I should do this only once when initializing the router. Could this be a security issue?

+5
source share
1 answer

You are doing it right already. If you use a standard named database, you can even omit the second statement. orm.NewOrm establishes a new relationship, not necessarily a new database connection. This ratio is necessary in the controller so that your data can be mapped to the correct database calls, after all, when another command is issued. As far as I have seen, this does not create any security problems.

+2
source

Source: https://habr.com/ru/post/1232529/


All Articles