zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 346 forks source link

Execution time logging #645

Open mosyp opened 7 years ago

mosyp commented 7 years ago

We need to add queries execution time logging

@getquill/maintainers

jilen commented 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
Nickersoft commented 6 years ago

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?

jilen commented 6 years ago

@Nickersoft I guess super.executeQuery[T](...) may help

Nickersoft commented 6 years ago

@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 commented 6 years ago

Use extractor instead of identity function like this

Nickersoft commented 6 years ago

@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!

jilen commented 6 years ago

@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