Open andradei opened 4 years ago
Queries in sqlboiler can only be re-used by substituting arguments, and even then only with a special call: https://github.com/volatiletech/sqlboiler/blob/master/queries/query.go#L203-L209
The reason for this is caching. When you run a query for the first time the sql is generated and saved into the query object:
https://github.com/volatiletech/sqlboiler/blob/master/queries/query_builders.go#L26-L27 https://github.com/volatiletech/sqlboiler/blob/master/queries/query_builders.go#L39-L41
It may be possible to invalidate the cache on finalizers. It does seem like reasonable thing to do doesn't it?
Thanks for linking the lines of code that do this. Now I understand the process whereas before (when I opened the issue) I was just guessing.
It may be possible to invalidate the cache on finalizers. It does seem like reasonable thing to do doesn't it?
That would be good. So calling a finalizer again without setting a new value could generate an error.
If you're having a generation problem please answer these questions before submitting your issue. Thanks!
What version of SQLBoiler are you using (
sqlboiler --version
)?SQLBoiler v3.6.1
What is your database and version (eg. Postgresql 10)
Postgresql 11.5
If this happened at runtime what code produced the issue? (if not applicable leave blank)
Further information. What did you do, what did you expect?
I wanted to keep the code DRY by having a
myQuery
variable that I could reuse. But apparently that doesn't work. The code runs without a problem, butthing
turns out to be the zero-valuedmodels.Thing
.Is it an implementation idiosyncrasy of
database/sql
or ofsqlboiler
?I know that not reusing
myQuery
fixes the problem, so it might not be a problem at all. But this was a little tricky to figure out at first. Seems likemyQuery
is consumed when it is run by the first Finisher, in this case,Exists()
.