Chapter 3 of Lift in Action is interesting because it reveals the elegance and simplicity of Lift’s View-Snippet-Model and templating system, actually showing how one would approach a workflow, from View First design and designer deliverables to template nesting and menu building, and from application requirements to business object modeling. In the midst of all this, the active record-like Mapper “ORM” is presented in quite useful fashion. You can find the code (in my repo, which is fully compatible with Lift 2.5 and sbt 0.12) here (at Tag “chapter03”): https://github.com/victorkane/LiftInActionAuctionApp/tree/chapter03
For development, it is quite common to use the built in H2 database engine, and this is no exception. So while it’s very cool I don’t have to start installing “stacks” of base software just to run the code, how do I get to visualize the database, as I would with, say, Phpmyadmin for MySql? The Lift community continues to impress in this case by conveniently documenting two ways:
- The Lift Cookbook entry Viewing the lift_proto H2 Database which explains how to use H2’s built-in web interface to independently view the database.
- A more refined alternative, referenced there, to actually map access to the web interface right into your Lift runtime code (which I have worked into my repo code for Chapter 3), found in an article in Diego Medina’s blog.
Following the instructions in the latter blog post, I inserted the appropriate code into various files, as can be clearly seen in the corresponding commit: https://github.com/victorkane/LiftInActionAuctionApp/commit/01c82226cce8f386473a656283c05da0303e302a. Then, after executing the app from within sbt in the usual way (i.e. “container:start” or “~; container:start; container:reload /”), I navigated to http://localhost:8080/console, entered jdbc:h2:database/temp in the JDBC URL field (the name of the database is to be found in Boot::boot (src/main/scala/bootstrap/liftweb/Boot.scala):
object Database extends StandardDBVendor(
Props.get("db.class").openOr("org.h2.Driver"),
Props.get("db.url").openOr("jdbc:h2:database/temp"),
Props.get("db.user"),
Props.get("db.pass"))
and then clicked on the Connect button without entering username or password. I clicked on CUSTOMERS, and then executed the generated view query by clicking on Run (Ctrl+Enter) and was able to visualize the data from my signing up at http://localhost:8080/account/sign_up.