Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GreenDao support for unique constraint on multiple columns

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)
);
like image 924
dominus Avatar asked Feb 27 '14 13:02

dominus


2 Answers

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

like image 146
Joel Brito Avatar answered Sep 16 '22 18:09

Joel Brito


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

@Entity(
    indexes = {
       @Index(value = "column1,column2,column3", unique = true)
    }
)
like image 40
Dan Chaltiel Avatar answered Sep 17 '22 18:09

Dan Chaltiel