【发布时间】:2014-08-16 05:01:52
【问题描述】:
我已经针对数据库 (sqlserver db) 运行了自动生成器,它生成了许多表定义。
我正在寻找使用这些定义来填充新数据库 - 我以为我会使用 Tables.ddl.create,但我看到编译错误 (value create is not a member of app.db.Tables.profile.DDL)
另外,一旦创建了一个表,填充它的规范模式是什么? (自动生成的代码似乎不包含 * 投影 - 这是故意的吗?)
示例自动生成的表定义:
/** Entity class storing rows of table SampleTable
* @param sampletableid Database column SampleTableId DBType(uniqueidentifier), Length(36,false)*/
case class SampleTableRow(sampletableid: Option[String])
/** GetResult implicit for fetching SampleTableRow objects using plain SQL queries */
implicit def GetResultSampleTableRow(implicit e0: GR[Option[String]], e1: GR[Int], e2: GR[Option[java.sql.Clob]], e3: GR[java.sql.Timestamp]): GR[SampleTableRow] = GR{
prs => import prs._
SampleTableRow.tupled((<<?[String]))
}
/** Table description of table SampleTable. Objects of this class serve as prototypes for rows in queries. */
class SampleTable(_tableTag: Tag) extends Table[SampleTableRow](_tableTag, Some("dbo"), "SampleTable") {
def * = (sampletableid) <> (SampleTableRow.tupled, SampleTableRow.unapply)
/** Maps whole row to an option. Useful for outer joins. */
def ? = (sampletableid).shaped.<>({r=>import r._; _3.map(_=>SampleTableRow.tupled((_1)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
/** Database column SampleTableId DBType(uniqueidentifier), Length(36,false) */
val sampletableid: Column[Option[String]] = column[Option[String]]("SampleTableId", O.Length(36,varying=false))
}
/** Collection-like TableQuery object for table SampleTable */
lazy val SampleTable = new TableQuery(tag => new SampleTable(tag))
【问题讨论】:
-
我从未将模式生成器与 SQL 数据库(仅 PostgreSQL 和 MySQL)一起使用,但据我所知,投影方法应该是自动生成的。
-
绝对不存在,对于我的 20 个左右的表定义中的任何一个
-
您能在问题中添加一个表定义吗?
-
只需使用将转换为查询的巧妙方法(插入、删除、过滤等)。或者你可以编写一个通用的表对象,在其中添加所有必要的方法并让其他表从它继承。
-