Execution
In this section we'll learn how to execute queries in various modes as well as how we unmarshall the data into a Go structure. We'll also learn how to execute multiple query blocks
Execute Query#
In order to execute a query we must run the Execute method.
Every time we call Execute a new transaction is created, and it is committed upon success.
Manual Transaction#
if you want control over the transaction you can certainly do that.
We do that passing dqlx.WithTnx() function to the Execute method
Read Only Transaction#
Similarly, we use WithReadOnly if we want to mark this query to be read-only
Unmarshalling#
Once the query is executed successfully, we want to grab the result set and Unmarshall it into a go data structure.
We can Unmarshall the results by calling Unmarshall on the response object.
Another way to achieve the same as above but with fewer lines of code is to use the UnmarshallInto method during the building phase.
Structs#
You can also Unmarshall into well-defined structs, which is usually the recommended way.
The marshaller takes in consideration the json: tag of the field to automatically map the data.