Search code examples
databasescalalift

Getting Started With Lift, Using Databases to Build Dynamic Sites


So I have been looking around the internet for a good explanation of how lift works concerning databases. I have not found anything very helpful yet. What I am looking for is a simple explanation or code example that can show how lift connects to its databases to perform transactions and how to use this to create new tables, models or update and edit existing tables.

For example: with django i fairly easily figured out how it generated database tables from model classes and executed updates on them through methods it inherited from the framework.

I am trying to create a simple app at the moment that would have users, information about them, posts on a website, etc.

I am currently reading through the available Lift books and would greatly appreciate more help in learning how to use lift.


Solution

  • Lift configures it's data source in Boot.scala.

    if (!DB.jndiJdbcConnAvailable_?) {
      val vendor =
        new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
          Props.get("db.url") openOr
            "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
          Props.get("db.user"), Props.get("db.password"))
    
    
      LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
    
      DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
    }
    

    It can generate table schemas for you using Schemifier:

     Schemifier.schemify(true, Schemifier.infoF _, User,Post,Tag,PostTags)
    

    For general Lift project, you can just use Lift Mapper as an ORM tool, it's not complete but works for most of the cases.

    You can refer to Lift WIKI and Simply Lift(Written by the Author) or Explore Lift. From my perspective, the documents available so far are rather disappointing. It's said the Lift in Action is very well written, but won't come out till this summer, you can read it from MEAP.