Lift 入门,使用数据库构建动态站点

发布于 2024-10-18 22:01:57 字数 300 浏览 1 评论 0原文

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

例如:使用 django,我相当容易地弄清楚它如何从模型类生成数据库表,并通过从框架继承的方法对它们执行更新。

我目前正在尝试创建一个简单的应用程序,其中包含用户、有关用户的信息、网站上的帖子等。

我目前正在阅读可用的 Lift 书籍,并且非常感谢在学习如何使用 lift 方面获得更多帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剩一世无双 2024-10-25 22:01:57

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)
}

它可以使用Schemifier为您生成表模式:

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

对于一般的Lift项目,您可以仅使用Lift Mapper作为ORM工具,它并不完整,但适用于大多数情况。

您可以参考Lift WIKI和Simply Lift(作者撰写)或Explore Lift
从我的角度来看,迄今为止提供的文件相当令人失望。
据说Lift in Action写得很好,但要到今年夏天才会出来,你可以从 MEAP 上阅读。

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.

残龙傲雪 2024-10-25 22:01:57

在《Exploring Lift》一书中,PocketChange 示例包含展示如何使用 MetaProtoUser 和其他功能定义用户的代码。我将从这里开始,以便更好地理解 Lift、模型以及内置的 CRUD 和用户原型对象。

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

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

您还可以查看 Lift in Action 的来源以获得一些想法。这是前几章中构建的旅行应用程序的链接
https://github.com/timperrett/lift-travel

以及整个源代码书。第 10 章是映射器章节。
https://github.com/timperrett/lift-in-action

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

流殇 2024-10-25 22:01:57

Lift 中的默认 ORM 是 Mapper,它为您提供了数据库实体的 CRUD 功能的快速路径。
但是,如果您想要更传统的 JPA 持久性方法(或者更确切地说 SPA,因为在这种情况下实体将用 scala 编写),我通常会发现作为 Lift 发行版一部分的类似 JPA 的示例应用程序非常有用。要尝试一下,假设安装了 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

这将创建一个 MyProject Lift 项目,其中包含一个简单的图书馆应用程序,其中有 2 个具有一对多关系的实体(作者和书籍)以及显示如何使用的 CRUD 片段。可以在符合 jdbc 的数据库中创建和编辑此类实体。

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:

   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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文