6

Does GreenDao supports unique constraint on multiple columns? Equivalent of the following:

create table projects (
  _id integer primary key autoincrement,
  project_type text,
  name text,
  unique (project_type, name)
);
dominus
  • 1,082
  • 1
  • 11
  • 14

2 Answers2

13

Yes, it supports.

Create an index with all the properties and make it unique.

Index indexUnique = new Index();
indexUnique.addProperty(project_type);
indexUnique.addProperty(name);
indexUnique.makeUnique();
projectsEntity.addIndex(indexUnique);

Source

Joel Brito
  • 339
  • 3
  • 9
10

As for version 3.2.0, you can declare multiple indexes in the Entity declaration :

@Entity(
    indexes = {
       @Index(value = "column1,column2,column3", unique = true)
    }
)
Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92