GreenDao支持多列的唯一约束

dom*_*nus 6 android greendao

GreenDao是否支持多列的唯一约束?相当于以下内容:

create table projects (
  _id integer primary key autoincrement,
  project_type text,
  name text,
  unique (project_type, name)
);
Run Code Online (Sandbox Code Playgroud)

小智 13

是的,它支持.

创建包含所有属性的索引并使其唯一.

Index indexUnique = new Index();
indexUnique.addProperty(project_type);
indexUnique.addProperty(name);
indexUnique.makeUnique();
projectsEntity.addIndex(indexUnique);
Run Code Online (Sandbox Code Playgroud)

资源

  • 我们需要在哪个文件或哪个文件中添加这些代码? (2认同)

Dan*_*iel 10

对于版本3.2.0,您可以在实体声明中声明多个索引:

@Entity(
    indexes = {
       @Index(value = "column1,column2,column3", unique = true)
    }
)
Run Code Online (Sandbox Code Playgroud)