Beego: Creating a new orm before every request?
Asked Answered
H

1

7

Currently I'm using 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 feels like I should do that only once at router initialization. Can that be a security issue?

Haftarah answered 29/9, 2015 at 11:47 Comment(0)
V
4

You are doing it correctly already. If you are using the default named database you can even omit the second statement. orm.NewOrm sets up a new relationship, not necessarily a new database connection. This relationship is necessary in the controller so that your data can be mapped to the correct database calls eventually when another command is issued. As far as I have seen this does not pose any security issues.

Vanpelt answered 13/10, 2015 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.