Query a MySQL DB.
I've created an InitDB function which basically opens a connection with that database.
The question is, is it best practice to simply initiate the connection in the main function and leave it at that? My approach is to InitDB in every function that queries the DB and then defer rows.Close()
What do y'all suggest?
I think you should create one function that is supposed to query the database and whichever function needs data can call that function to get data, it'll reduce repetition.
I personally use a simple version of connection pooling
Обсуждают сегодня