When doing sqlair.Prepare, SQLair will not throw an error if you pass extra types that are not used in the query. This refactor is motivated by the need to add this error.
The BindTypes function used ArgInfo from the typeinfo package to get information about the arguments. The ArgInfo object has methods that allow BindTypes to pass simply the name of the type needed and they will return all the relevent information about the type or an error message if it is not found. The typeinfo package is only concerned with getting information about types, and does not do any storing of state.
A simple (but wrong) way to track which types have been used during prepare would be to add state to this ArgInfo object, and when BindTypes was finished, it could be queried to see if all types had been used. However, this would add state to ArgInfo
Another way to do this would be to keep track of the arguments used in BindTypes directly, however, the level of abstraction here is wrong, several layers have to be unwrapped to get the type information.
The solution I have landed upon is adding an extra layer in-between ArgInfo and the bindTypes functions on the typed expressions. This follows a similar pattern to the query builder in the BindInputs stage. The ArgInfo object arguably had too much responsibility considering that it was designed only to be concerned with types. Therefore, it was natural to transfer some of this to the new typedExprBulider layer which is now responsible for finding the arguments in the map returned from GenerateArgInfo and also with the keeping track of outputs and arguments used.
When doing
sqlair.Prepare
, SQLair will not throw an error if you pass extra types that are not used in the query. This refactor is motivated by the need to add this error.The
BindTypes
function usedArgInfo
from thetypeinfo
package to get information about the arguments. TheArgInfo
object has methods that allowBindTypes
to pass simply the name of the type needed and they will return all the relevent information about the type or an error message if it is not found. Thetypeinfo
package is only concerned with getting information about types, and does not do any storing of state.A simple (but wrong) way to track which types have been used during prepare would be to add state to this
ArgInfo
object, and whenBindTypes
was finished, it could be queried to see if all types had been used. However, this would add state toArgInfo
Another way to do this would be to keep track of the arguments used in
BindTypes
directly, however, the level of abstraction here is wrong, several layers have to be unwrapped to get the type information.The solution I have landed upon is adding an extra layer in-between
ArgInfo
and thebindTypes
functions on the typed expressions. This follows a similar pattern to the query builder in theBindInputs
stage. TheArgInfo
object arguably had too much responsibility considering that it was designed only to be concerned with types. Therefore, it was natural to transfer some of this to the newtypedExprBulider
layer which is now responsible for finding the arguments in the map returned fromGenerateArgInfo
and also with the keeping track of outputs and arguments used.