Skip to content

Logging and debugging

Yuki Yoshinoya edited this page Feb 9, 2015 · 6 revisions

There are few ways of seeing the generated SQL

1) Using com.github.aselab.activerecord.inner.Relation#toSql

For example:

println(User.where(_.name like "john%").orderBy(_.age desc).toSql)

2) Set level logging to DEBUG

Using Logback, customize the xml configuration: (e.g.: src/main/resources/logback.xml)

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%highlight(%-5level) %cyan(%logger{15}) - %msg %n</pattern>
    </encoder>
  </appender>
  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

You will see every statements, and a dump of result sets of the seesion.

Use sbt console

Add the following settings in build.sbt or project/Build.scala.

initialCommands in console := """
import com.github.aselab.activerecord._
import com.github.aselab.activerecord.dsl._
import models._
SomeTables.initialize
"""
> console
scala> User.forceInsertAll{ (1 to 10000).map{i => User("name" + i)} }
scala> User.where(_.name === "name10").toList