从Lift开始,使用数据库构建动态站点

时间:2021-02-21 19:09:52

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.

所以我一直在互联网上寻找一个关于lift是如何工作的关于数据库的很好的解释。我还没有发现任何有用的东西。我正在寻找的是一个简单的解释或代码示例,它可以显示lift如何连接到它的数据库来执行事务,以及如何使用它来创建新的表、模型或更新和编辑现有的表。

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.

例如:通过django,我可以很容易地找到如何从模型类生成数据库表,并通过从框架继承的方法对它们执行更新。

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.

我目前正在阅读现有的升降机书籍,并非常感谢更多的帮助来学习如何使用升降机。

3 个解决方案

#1


3  

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

Lift配置它在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生成表模式:

 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.

对于一般的升降机项目,您可以使用升降机映射器作为ORM工具,它不完整,但适用于大多数情况。

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.

你可以参考Lift WIKI,简单的Lift(作者写的)或者Explore Lift。在我看来,目前所提供的文件相当令人失望。据说《电梯运行》写得很好,但要到今年夏天才能上映,你可以从MEAP上读到。

#2


2  

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.

在探索电梯的书中,PocketChange示例包含如何使用元保护程序和其他特性定义用户的代码。我将从那里开始更好地理解Lift、model和内置CRUD以及用户原型对象。

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

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

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.

记住,DB集成的“新”方法将通过记录进行。这是一项正在进行中的工作,所以我不会急于开始学习它。

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

您还可以查看Lift的源代码以获得一些想法。以下是前两章中构建的旅游应用程序的链接: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

以及整本书的源代码。第十章是制图章。https://github.com/timperrett/lift-in-action

#3


1  

The default ORM in Lift is Mapper which gives you among other things a quick path to CRUD functionality for your DB entities. However if you would like a more traditional JPA persistence approach (or rather SPA since entities would in that case be written in scala), i usually find very useful the JPA-like sample application that is part of the Lift distribution. To try it out, assuming maven is installed, just type:

Lift中的默认ORM是Mapper,它为DB实体提供了CRUD功能的快速路径。但是,如果您希望采用更传统的JPA持久性方法(或者更确切地说是SPA,因为实体在这种情况下是用scala编写的),我通常会发现类似JPA的示例应用程序非常有用,它是Lift发行版的一部分。要尝试它,假设安装了maven,只需输入:

   mvn archetype:generate -DarchetypeRepository=http://scala-tools.org/repo-snapshots -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-jpa-basic_2.8.1 -DarchetypeVersion=2.3-SNAPSHOT -DgroupId=org.mycompany.myproject -DartifactId=MyProject -Dversion=1.0

This will create a MyProject Lift project, containing a simple library application with 2 entities (Author and Book) having a one-to-many relationship as well as CRUD snippets showing how you can create and edit such entities in a jdbc compliant database.

这将创建一个MyProject Lift项目,其中包含一个简单的库应用程序,其中包含两个实体(作者和图书),它们具有一对多关系,以及CRUD片段,显示如何在兼容jdbc的数据库中创建和编辑这些实体。

#1


3  

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

Lift配置它在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生成表模式:

 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.

对于一般的升降机项目,您可以使用升降机映射器作为ORM工具,它不完整,但适用于大多数情况。

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.

你可以参考Lift WIKI,简单的Lift(作者写的)或者Explore Lift。在我看来,目前所提供的文件相当令人失望。据说《电梯运行》写得很好,但要到今年夏天才能上映,你可以从MEAP上读到。

#2


2  

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.

在探索电梯的书中,PocketChange示例包含如何使用元保护程序和其他特性定义用户的代码。我将从那里开始更好地理解Lift、model和内置CRUD以及用户原型对象。

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

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

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.

记住,DB集成的“新”方法将通过记录进行。这是一项正在进行中的工作,所以我不会急于开始学习它。

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

您还可以查看Lift的源代码以获得一些想法。以下是前两章中构建的旅游应用程序的链接: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

以及整本书的源代码。第十章是制图章。https://github.com/timperrett/lift-in-action

#3


1  

The default ORM in Lift is Mapper which gives you among other things a quick path to CRUD functionality for your DB entities. However if you would like a more traditional JPA persistence approach (or rather SPA since entities would in that case be written in scala), i usually find very useful the JPA-like sample application that is part of the Lift distribution. To try it out, assuming maven is installed, just type:

Lift中的默认ORM是Mapper,它为DB实体提供了CRUD功能的快速路径。但是,如果您希望采用更传统的JPA持久性方法(或者更确切地说是SPA,因为实体在这种情况下是用scala编写的),我通常会发现类似JPA的示例应用程序非常有用,它是Lift发行版的一部分。要尝试它,假设安装了maven,只需输入:

   mvn archetype:generate -DarchetypeRepository=http://scala-tools.org/repo-snapshots -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-jpa-basic_2.8.1 -DarchetypeVersion=2.3-SNAPSHOT -DgroupId=org.mycompany.myproject -DartifactId=MyProject -Dversion=1.0

This will create a MyProject Lift project, containing a simple library application with 2 entities (Author and Book) having a one-to-many relationship as well as CRUD snippets showing how you can create and edit such entities in a jdbc compliant database.

这将创建一个MyProject Lift项目,其中包含一个简单的库应用程序,其中包含两个实体(作者和图书),它们具有一对多关系,以及CRUD片段,显示如何在兼容jdbc的数据库中创建和编辑这些实体。