Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 241
RedbeardTheNinja Avatar asked Feb 23 '11 04:02

RedbeardTheNinja


2 Answers

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.

like image 165
Sawyer Avatar answered Sep 25 '22 08:09

Sawyer


In the Exploring Lift book, the PocketChange example contains code showing how to define a User using MetaProtoUser and other features. I would start there for a better understanding of Lift, model and the built-in CRUD and User prototype objects.

http://exploring.liftweb.net/master/index-2.html#toc-Chapter-2

Keep in mind that the 'new' approach to DB integration will be via the Record. This is very much a work in progress, so I wouldn't rush to start learning it.

You can also look at the source for Lift in Action to get some ideas. Here's a link to the travel app built in the first couple chapters https://github.com/timperrett/lift-travel

And to the source code for the entire book. Chapter 10 is the Mapper chapter. https://github.com/timperrett/lift-in-action

like image 43
Mikezx6r Avatar answered Sep 24 '22 08:09

Mikezx6r