我正在为Slick命令寻找postgresql的翻译 它看起来很简单,但我找不到任何可以实现的东西:
CREATE TABLE mytable (
id serial PRIMARY KEY,
type varchar (50) NOT NULL,
...
location varchar(25) check (location in ('north', 'south', 'west', 'east')),
...
created date
);
您如何定义线路
location varchar(25) check (location in ('north', 'south', 'west', 'east', 'northeast', 'southeast', 'southwest', 'northwest'))
在Slick?
我有兴趣将这些检查应用于db级别的字符串健全性 (我目前在代码级别执行它们)
欢迎任何帮助!
答案 0 :(得分:1)
创建ENUM类型可能会更好吗?考虑一下这项工作。
CREATE TYPE location AS ENUM (
'north',
'south',
'west',
'east'
);
CREATE TABLE mytable (
id serial PRIMARY KEY,
type varchar (50) NOT NULL,
...
location location,
...
created date
);