3

我需要在表上添加列约束,如下所示:

更改表 CH

add constraint CH_N_TYPE_CHK check (N_TYPE = 'bc' or N_TYPE = 'pub');

这样插入的所有值都CH.N_TYPE应该是bc或者pub只是。

我想使用 slick 的 table.ddl 来创建表格。
我认为它可能涉及约束类,但它似乎只支持外键或索引,我在 slick 或 slick-test-kit 上搜索了代码但找不到任何提示。在光滑的桌子上可行吗?

4

1 回答 1

0

I didn't find anything related to check in the constraint usage, the only way that I find out was to use a enumeration in your column.

CH(tag:Tag) extends Table[CHRow]("ch") {
val nType: Column[NType.Value] = column[NType.Value]("N_TYPE")
implicit val enumMapper = MappedColumnType.base[NType.Value, String](_.toString(),  NType.withName(_))
.
.
.
}

And define your enumeration as follows abstract class NType extends Enumeration { val BC = Value val PUB = Value }

With this you can only insert values BC or PUB int your column. The code above follows the patterns for slick 2.0, but with some little modifications you can use it in slick 1.

于 2014-01-03T18:50:03.613 回答