Dennis,
You’re not using statements but instead using what I stated works for me as well which is to just run the query directly. However, I wanted to point out a few things you might want to consider.
-
You are creating your db connection within each function. From what I’ve been told you really only need one db connection created in main and then used as a global variable in the other functions. This will speed things up dramatically.
-
I think you might be using defer too late. The reason for having a defer statement is to make sure something happens no matter what. Closing the db connection is your example but what happens if your code dies before it gets down to the bottom of the function to close the connection. So instead what you want to do is create the connection and immediately tell it to defer close. Then if something happens before it gets to the bottom it will still close the connection for you. The way you’re using it you might as well just replace it with a close and remove the defer.