在Scala(任何框架)中是否有一个CRUD生成器实用程序,如Rails中的Scaffolding?

时间:2013-02-01 15:31:19

标签: ruby-on-rails scala crud scaffolding

请参阅:Is there a CRUD generator utility in Java(any framework) like Scaffolding in Rails?

我有同样的问题但是关于Scala。我知道Play框架1.x有生成器,但2.x删除它们,是否有任何可用于任何基于Scala的Web框架的CRUD / Scaffolding生成器?

2 个答案:

答案 0 :(得分:2)

我也在寻找一个脚手架工具(突出你的问题)并找到了这个:http://skinny-framework.org/documentation/scaffolding.html

我做了尝试了但是文档看起来像是要做这个工作:

./skinny g model tweet userId:Long text:String user:Option[User] 将创建

package model

import skinny.orm._, feature._
import scalikejdbc._
import org.joda.time._

// If your model has +23 fields, switch this to normal class and mixin scalikejdbc.EntityEquality.
case class Tweet(
  id: Long,
  userId: Long,
  text: String,
  user: Option[User] = None,
  createdAt: DateTime,
  updatedAt: DateTime
)

object Tweet extends SkinnyCRUDMapper[Tweet] with TimestampsFeature[Tweet] {

  override lazy val defaultAlias = createAlias("t")

  lazy val userRef = belongsTo[User](User, (t, u) => t.copy(user = u))

  /*
   * If you're familiar with ScalikeJDBC/Skinny ORM, using #autoConstruct makes your mapper simpler.
   * (e.g.)
   * override def extract(rs: WrappedResultSet, rn: ResultName[Tweet]) = autoConstruct(rs, rn)
   *
   * Be aware of excluding associations like this:
   * (e.g.)
   * case class Member(id: Long, companyId: Long, company: Option[Company] = None)
   * object Member extends SkinnyCRUDMapper[Member] {
   *   override def extract(rs: WrappedResultSet, rn: ResultName[Member]) =
   *     autoConstruct(rs, rn, "company") // "company" will be skipped
   * }
   */
  override def extract(rs: WrappedResultSet, rn: ResultName[Tweet]): Tweet = new Tweet(
    id = rs.get(rn.id),
    userId = rs.get(rn.userId),
    text = rs.get(rn.text),
    createdAt = rs.get(rn.createdAt),
    updatedAt = rs.get(rn.updatedAt)
  )
}

希望这有帮助!

答案 1 :(得分:1)

从评论中复制答案,以便从“未答复”过滤器中删除此问题:

  

不,是关于这个游戏用户组的一些话题,没有任何计划。 Twitter Bootstrap + DAO实现+ RESTful路由是您最好的选择;即推出自己的。

     

...

     

检查有关整合TB [Twitter Bootstrap]的文档,非常棒,给你一个很棒的开端,使用Play的CRUD相当容易。

〜每virtualeyes

回答