Open mosyp opened 7 years ago
You can extends underlying Context
, then overriding those methods to log execution time
def executeQuery
def executeQuerySingle
def executeAction
def executeActionReturning
def executeBatchAction
def executeBatchActionReturning
Hi @jilen, I'm trying to achieve execution time logging as well and have tried overriding the methods as you have mentioned. However, I'm running into an issue considering those methods seem to be generic. This block alone causes an error:
class DatabaseContext extends PostgresJdbcContext[SnakeCase](SnakeCase, new HikariDataSource(/* my config */)) {
override def executeQuery[T](sql: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor): List[T] = {
return super.executeQuery(sql, identityPrepare, identityExtractor)
}
}
I get an error around identityExtractor
stating:
"Expression of type DatabaseContext.this.ResultRow => DatabaseContext.this.ResultRow doesn't conform to expected type DatabaseContext.this.Extractor[T]"
and on my return statement I get the error:
"Expression of type List[DatabaseContext.this.ResultRow] does not conform to expected type List[T]"
of course, replace T
with ResultRow
fixes these issues, but at that point, I receive an error saying my method isn't overriding the original method anymore. I looked around online and it seems rather difficult to effectively override generic methods. What did you have in mind?
@Nickersoft I guess super.executeQuery[T](...)
may help
@jilen Oh wow that actually did fix the error on the return line.. so thank you! However, it still thinks that identityExtractor
is a ResultRow => ResultRow
type instead of an Extractor
.. any idea why that might be?
@jilen Hmmm it's still complaining about the identityExtractor
default value parameter assignment type mismatch, but it's compiling so I guess that's good enough for me! Thanks!
@Nickersoft identifyExtractor
and identifyPrepare
is just a function like
def identify[T](x: T): T = x
What you need to pass to parent is actually prepare
and extractor
, but not identityPrepare
, identityExtractor
We need to add queries execution time logging
@getquill/maintainers